Skip to content

Commit

Permalink
Fix code to obtain Python relative install dir in Python 3.12
Browse files Browse the repository at this point in the history
As the code in some cases return slightly different results then the previous version (see robotology/robotology-superbuild#1238 (comment)), we only use it when Python >= 3.12. This is simar to robotology/robotology-superbuild#1511
  • Loading branch information
GiulioRomualdi committed Mar 24, 2024
1 parent 7531210 commit 80080f2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ if(IDYNTREE_USES_PYTHON OR IDYNTREE_USES_PYTHON_PYBIND11)
if(IDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES)
set(IDYNTREE_PYTHON_INSTALL_DIR ${Python3_SITELIB})
else()
execute_process(COMMAND ${Python3_EXECUTABLE}
-c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))"
OUTPUT_VARIABLE _PYTHON_INSTDIR)
if(Python3_VERSION VERSION_GREATER_EQUAL 3.12)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import os;import sysconfig;relative_site_packages = sysconfig.get_path('purelib').replace(sysconfig.get_path('data'), '').lstrip(os.path.sep);print(relative_site_packages)"
OUTPUT_VARIABLE _PYTHON_INSTDIR)
else()
execute_process(COMMAND ${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))"
OUTPUT_VARIABLE _PYTHON_INSTDIR)
endif()
string(STRIP ${_PYTHON_INSTDIR} IDYNTREE_PYTHON_INSTALL_DIR)
endif()
endif()
Expand Down

0 comments on commit 80080f2

Please sign in to comment.