diff options
author | Aaron Rossetto <aaron.rossetto@ni.com> | 2022-01-06 13:06:23 -0600 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2022-01-14 14:36:39 -0600 |
commit | 87bc7c1bde9e4994c164bb3c19fd7acf25189a7d (patch) | |
tree | 476f3516787432d6cc24f723078d117e054a9ed1 /mpm/python/CMakeLists.txt | |
parent | 6d746fd2963a8461cb38efb4189388f96bf1f93e (diff) | |
download | uhd-87bc7c1bde9e4994c164bb3c19fd7acf25189a7d.tar.gz uhd-87bc7c1bde9e4994c164bb3c19fd7acf25189a7d.tar.bz2 uhd-87bc7c1bde9e4994c164bb3c19fd7acf25189a7d.zip |
cmake: Replace distutils.sysconfig with sysconfig
This commit replaces uses of distutils.sysconfig's get_python_lib()
function with sysconfig's near-equivalent get_path() function to get the
directory for site-specific, platform-specific files. Unfortunately,
get_path() does not have a way to easily modify or strip the prefix
applied to the path like get_python_lib() does, so the code must
manually modify the path to get the same effect:
- First, the platlib path is retrieved from the get_path() call.
- Next, the default base that is used to form the pathlib path is
queried via the get_config_var('base') call.
- Next, the portion of the platlib path that matches the default base is
stripped, and any leading path separator remaining is stripped. This
fundamentally replicates the behavior of get_python_lib() with an empty
prefix (i.e., the prefix positional parameter is specified as '').
- If a different prefix is desired, then the os.path.join() function is
used to combine the new prefix with the stripped pathlib path, ensuring
that the platform-specific path separator is used in crafting the path.
Diffstat (limited to 'mpm/python/CMakeLists.txt')
-rw-r--r-- | mpm/python/CMakeLists.txt | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/mpm/python/CMakeLists.txt b/mpm/python/CMakeLists.txt index d5106b1b3..260d3bab7 100644 --- a/mpm/python/CMakeLists.txt +++ b/mpm/python/CMakeLists.txt @@ -101,7 +101,10 @@ add_custom_command(OUTPUT ${OUTPUT} add_custom_target(usrp_mpm ALL DEPENDS ${OUTPUT} pyusrp_periphs) execute_process(COMMAND ${PYTHON_EXECUTABLE} -c - "from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix=''))" + "import sysconfig;\ + platlib = sysconfig.get_path(name='platlib');\ + base = sysconfig.get_config_var('base');\ + print(platlib.replace(base, '').lstrip('/\\\\'))" OUTPUT_VARIABLE USRP_MPM_PYTHON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/lib/usrp_mpm DESTINATION ${USRP_MPM_PYTHON_DIR}) |