Skip to content

Commit

Permalink
00251: Change user install location
Browse files Browse the repository at this point in the history
Set values of prefix and exec_prefix in distutils install command
to /usr/local if executable is /usr/bin/python* and RPM build
is not detected to make pip and distutils install into separate location.

Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
Downstream only: Awaiting resources to work on upstream PEP
  • Loading branch information
mcyprian authored and hroncok committed Oct 4, 2021
1 parent 3cebdae commit a992f71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Lib/distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,19 @@ 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 is set to sys.prefix + /local/
# if neither RPM build nor virtual environment is
# detected to make pip and distutils install packages
# into the separate location.
if (not (hasattr(sys, 'real_prefix') or
sys.prefix != sys.base_prefix) and
'RPM_BUILD_ROOT' not in os.environ):
addition = "/local"
else:
addition = ""

self.prefix = os.path.normpath(sys.prefix) + addition
self.exec_prefix = os.path.normpath(sys.exec_prefix) + addition

else:
if self.exec_prefix is None:
Expand Down
9 changes: 8 additions & 1 deletion Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,15 @@ 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.
"""
_trace("Processing global site-packages")
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)
Expand Down

0 comments on commit a992f71

Please sign in to comment.