Skip to content

Commit 1b1b25b

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 1b1b25b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ament_cmake_python/ament_cmake_python-extras.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ macro(_ament_cmake_python_get_python_install_dir)
4747
set(_python_code
4848
"\
4949
import os
50+
import re
5051
import sysconfig
51-
schemes = sysconfig.get_scheme_names()
5252
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'
53+
if not re.match(r'^/usr/?$', '${CMAKE_INSTALL_PREFIX}'):
54+
schemes = sysconfig.get_scheme_names()
55+
if 'deb_system' in schemes or 'osx_framework_library' in schemes:
56+
kwargs['scheme'] = 'posix_prefix'
57+
elif 'rpm_prefix' in schemes:
58+
kwargs['scheme'] = 'rpm_prefix'
5759
print(os.path.relpath(sysconfig.get_path('purelib', **kwargs), start='${CMAKE_INSTALL_PREFIX}').replace(os.sep, '/'))"
5860
)
5961
get_executable_path(_python_interpreter Python3::Interpreter CONFIGURE)

0 commit comments

Comments
 (0)