Skip to content

Commit 415b67a

Browse files
committed
Improve Python install path detection
This PR makes the customized Python path scheme logic in colcon contingent on an install prefix other than `/usr`. This makes colcon more distribution-friendly and prevents the accidental overwriting of system packages in case someone decides to install their packages to `/usr`. There is no other change in behavior. Signed-off-by: Timo Röhling <roehling@debian.org>
1 parent a6aef15 commit 415b67a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

colcon_core/python_install_path.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ def get_python_install_path(name, vars_=()):
1818
"""
1919
kwargs = {}
2020
kwargs['vars'] = dict(vars_)
21-
# Avoid deb_system because it means using --install-layout deb
22-
# which ignores --prefix and hardcodes it to /usr
23-
if 'deb_system' in sysconfig.get_scheme_names() or \
24-
'osx_framework_library' in sysconfig.get_scheme_names():
25-
kwargs['scheme'] = 'posix_prefix'
26-
# The presence of the rpm_prefix scheme indicates that posix_prefix
27-
# has been patched to inject `local` into the installation locations.
28-
# The rpm_prefix scheme is a backup of what posix_prefix was before it was
29-
# patched.
30-
elif 'rpm_prefix' in sysconfig.get_scheme_names():
31-
kwargs['scheme'] = 'rpm_prefix'
21+
22+
install_base = kwargs['vars'].get('base', sysconfig.get_config_var('base'))
23+
if install_base != '/usr':
24+
# If we are not actually installing to /usr, the default path scheme
25+
# may be inadequate. Check if we need to override.
26+
schemes = sysconfig.get_scheme_names()
27+
if 'deb_system' in schemes or 'osx_framework_library' in schemes:
28+
# Avoid deb_system because it requires using --install-layout deb
29+
# which ignores --prefix and hardcodes it to /usr
30+
kwargs['scheme'] = 'posix_prefix'
31+
elif 'rpm_prefix' in schemes:
32+
# The presence of the rpm_prefix scheme indicates that posix_prefix
33+
# has been patched to inject `local` into the installation
34+
# locations. The rpm_prefix scheme is a backup of what posix_prefix
35+
# was before it was patched.
36+
kwargs['scheme'] = 'rpm_prefix'
3237

3338
return Path(sysconfig.get_path(name, **kwargs))

0 commit comments

Comments
 (0)