Skip to content

Commit 42d0bdb

Browse files
mcyprianhrnciar
authored andcommitted
00251: Change user install location
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
1 parent ed9f5da commit 42d0bdb

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Lib/distutils/command/install.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,19 @@ def finalize_unix(self):
419419
raise DistutilsOptionError(
420420
"must not supply exec-prefix without prefix")
421421

422-
self.prefix = os.path.normpath(sys.prefix)
423-
self.exec_prefix = os.path.normpath(sys.exec_prefix)
422+
# self.prefix is set to sys.prefix + /local/
423+
# if neither RPM build nor virtual environment is
424+
# detected to make pip and distutils install packages
425+
# into the separate location.
426+
if (not (hasattr(sys, 'real_prefix') or
427+
sys.prefix != sys.base_prefix) and
428+
'RPM_BUILD_ROOT' not in os.environ):
429+
addition = "/local"
430+
else:
431+
addition = ""
432+
433+
self.prefix = os.path.normpath(sys.prefix) + addition
434+
self.exec_prefix = os.path.normpath(sys.exec_prefix) + addition
424435

425436
else:
426437
if self.exec_prefix is None:

Lib/site.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,14 @@ def getsitepackages(prefixes=None):
353353
return sitepackages
354354

355355
def addsitepackages(known_paths, prefixes=None):
356-
"""Add site-packages to sys.path"""
356+
"""Add site-packages to sys.path
357+
358+
'/usr/local' is included in PREFIXES if RPM build is not detected
359+
to make packages installed into this location visible.
360+
361+
"""
362+
if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ:
363+
PREFIXES.insert(0, "/usr/local")
357364
for sitedir in getsitepackages(prefixes):
358365
if os.path.isdir(sitedir):
359366
addsitedir(sitedir, known_paths)

0 commit comments

Comments
 (0)