diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py index aaa300efa96e6e..18f01f10d419da 100644 --- a/Lib/distutils/command/install.py +++ b/Lib/distutils/command/install.py @@ -3,6 +3,7 @@ Implements the Distutils 'install' command.""" import sys +import sysconfig import os from distutils import log @@ -142,6 +143,8 @@ class install(Command): negative_opt = {'no-compile' : 'compile'} + # Allow Fedora to add components to the prefix + _prefix_addition = getattr(sysconfig, '_prefix_addition', '') def initialize_options(self): """Initializes options.""" @@ -419,8 +422,10 @@ def finalize_unix(self): raise DistutilsOptionError( "must not supply exec-prefix without prefix") - self.prefix = os.path.normpath(sys.prefix) - self.exec_prefix = os.path.normpath(sys.exec_prefix) + self.prefix = ( + os.path.normpath(sys.prefix) + self._prefix_addition) + self.exec_prefix = ( + os.path.normpath(sys.exec_prefix) + self._prefix_addition) else: if self.exec_prefix is None: diff --git a/Lib/site.py b/Lib/site.py index 54ffc4fdc03fff..930b91813e3607 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -362,7 +362,14 @@ def getsitepackages(prefixes=None): return sitepackages def addsitepackages(known_paths, prefixes=None): - """Add site-packages to sys.path""" + """Add site-packages to sys.path + + '/usr/local' is included in PREFIXES if RPM build is not detected + to make packages installed into this location visible. + + """ + if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ: + PREFIXES.insert(0, "/usr/local") for sitedir in getsitepackages(prefixes): if os.path.isdir(sitedir): addsitedir(sitedir, known_paths) diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index e3f79bfde52948..e1241048760fb9 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -86,6 +86,23 @@ }, } +# Force pip to use distutils paths instead of sysconfig +# https://github.com/pypa/pip/issues/10647 +_PIP_USE_SYSCONFIG = False + +# This is used by distutils.command.install in the stdlib +# as well as pypa/distutils (e.g. bundled in setuptools). +# The self.prefix value is set to sys.prefix + /local/ +# if neither RPM build nor virtual environment is +# detected to make distutils install packages +# into the separate location. +# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe +if (not (hasattr(sys, 'real_prefix') or + sys.prefix != sys.base_prefix) and + 'RPM_BUILD_ROOT' not in os.environ): + _prefix_addition = "/local" + + _SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include', 'scripts', 'data')