Skip to content

Commit

Permalink
Improve Python install path detection
Browse files Browse the repository at this point in the history
[ This is the companion PR to
colcon/colcon-core#601 ]

This PR makes the customized Python path scheme logic in
ament_cmake_python contingent on an install prefix other than `/usr`.

This makes ament more distribution-friendly and prevents the accidental
overwriting of system packages in case someone decides to install their
Python packages to /usr. There is no other change in behavior.

Signed-off-by: Timo Röhling <[email protected]>
  • Loading branch information
roehling committed Nov 27, 2023
1 parent 4f6f349 commit 1b1b25b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ament_cmake_python/ament_cmake_python-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ macro(_ament_cmake_python_get_python_install_dir)
set(_python_code
"\
import os
import re
import sysconfig
schemes = sysconfig.get_scheme_names()
kwargs = {'vars': {'base': '${CMAKE_INSTALL_PREFIX}'}}
if 'deb_system' in schemes or 'osx_framework_library' in schemes:
kwargs['scheme'] = 'posix_prefix'
elif 'rpm_prefix' in schemes:
kwargs['scheme'] = 'rpm_prefix'
if not re.match(r'^/usr/?$', '${CMAKE_INSTALL_PREFIX}'):
schemes = sysconfig.get_scheme_names()
if 'deb_system' in schemes or 'osx_framework_library' in schemes:
kwargs['scheme'] = 'posix_prefix'
elif 'rpm_prefix' in schemes:
kwargs['scheme'] = 'rpm_prefix'
print(os.path.relpath(sysconfig.get_path('purelib', **kwargs), start='${CMAKE_INSTALL_PREFIX}').replace(os.sep, '/'))"
)
get_executable_path(_python_interpreter Python3::Interpreter CONFIGURE)
Expand Down

0 comments on commit 1b1b25b

Please sign in to comment.