Skip to content

Commit

Permalink
Improve Python install path detection
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
roehling committed Feb 21, 2024
1 parent a6aef15 commit 5359d6f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions colcon_core/python_install_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ def get_python_install_path(name, vars_=()):
"""
kwargs = {}
kwargs['vars'] = dict(vars_)
# Avoid deb_system because it means using --install-layout deb
# which ignores --prefix and hardcodes it to /usr
if 'deb_system' in sysconfig.get_scheme_names() or \
'osx_framework_library' in sysconfig.get_scheme_names():
kwargs['scheme'] = 'posix_prefix'
# The presence of the rpm_prefix scheme indicates that posix_prefix
# has been patched to inject `local` into the installation locations.
# The rpm_prefix scheme is a backup of what posix_prefix was before it was
# patched.
elif 'rpm_prefix' in sysconfig.get_scheme_names():
kwargs['scheme'] = 'rpm_prefix'

install_base = kwargs['vars'].get('base', sysconfig.get_config_var('base'))
if install_base != sysconfig.get_config_var('base'):
# If we are not actually installing to the default location, the default
# path scheme may be inadequate. Check if we need to override.
schemes = sysconfig.get_scheme_names()
if 'deb_system' in schemes or 'osx_framework_library' in schemes:
# Avoid deb_system because it requires using --install-layout deb
# which ignores --prefix and hardcodes it to /usr
kwargs['scheme'] = 'posix_prefix'
elif 'rpm_prefix' in schemes:
# The presence of the rpm_prefix scheme indicates that posix_prefix
# has been patched to inject `local` into the installation
# locations. The rpm_prefix scheme is a backup of what posix_prefix
# was before it was patched.
kwargs['scheme'] = 'rpm_prefix'

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

0 comments on commit 5359d6f

Please sign in to comment.