Skip to content

Commit 143bc1e

Browse files
committed
Improve Python install path detection
[ 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]>
1 parent 4f6f349 commit 143bc1e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ament_cmake_python/ament_cmake_python-extras.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ macro(_ament_cmake_python_get_python_install_dir)
4848
"\
4949
import os
5050
import sysconfig
51-
schemes = sysconfig.get_scheme_names()
5251
kwargs = {'vars': {'base': '${CMAKE_INSTALL_PREFIX}'}}
53-
if 'deb_system' in schemes or 'osx_framework_library' in schemes:
54-
kwargs['scheme'] = 'posix_prefix'
55-
elif 'rpm_prefix' in schemes:
56-
kwargs['scheme'] = 'rpm_prefix'
52+
if sysconfig.get_config_var('base') != os.path.normpath('${CMAKE_INSTALL_PREFIX}'):
53+
schemes = sysconfig.get_scheme_names()
54+
if 'deb_system' in schemes or 'osx_framework_library' in schemes:
55+
kwargs['scheme'] = 'posix_prefix'
56+
elif 'rpm_prefix' in schemes:
57+
kwargs['scheme'] = 'rpm_prefix'
5758
print(os.path.relpath(sysconfig.get_path('purelib', **kwargs), start='${CMAKE_INSTALL_PREFIX}').replace(os.sep, '/'))"
5859
)
5960
get_executable_path(_python_interpreter Python3::Interpreter CONFIGURE)

0 commit comments

Comments
 (0)