Skip to content

Commit e8e06f1

Browse files
mcyprianhroncok
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: Reworked in Fedora 36+/Python 3.10+ to follow https://bugs.python.org/issue43976 pypa/distutils integration: pypa/distutils#70 Also set sysconfig._PIP_USE_SYSCONFIG = False, to force pip-upgraded-pip to respect this patched distutils install command. See https://bugzilla.redhat.com/show_bug.cgi?id=2014513 Co-authored-by: Miro Hrončok <[email protected]>
1 parent 670c30f commit e8e06f1

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Lib/distutils/command/install.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Implements the Distutils 'install' command."""
44

55
import sys
6+
import sysconfig
67
import os
78

89
from distutils import log
@@ -142,6 +143,8 @@ class install(Command):
142143

143144
negative_opt = {'no-compile' : 'compile'}
144145

146+
# Allow Fedora to add components to the prefix
147+
_prefix_addition = getattr(sysconfig, '_prefix_addition', '')
145148

146149
def initialize_options(self):
147150
"""Initializes options."""
@@ -419,8 +422,10 @@ def finalize_unix(self):
419422
raise DistutilsOptionError(
420423
"must not supply exec-prefix without prefix")
421424

422-
self.prefix = os.path.normpath(sys.prefix)
423-
self.exec_prefix = os.path.normpath(sys.exec_prefix)
425+
self.prefix = (
426+
os.path.normpath(sys.prefix) + self._prefix_addition)
427+
self.exec_prefix = (
428+
os.path.normpath(sys.exec_prefix) + self._prefix_addition)
424429

425430
else:
426431
if self.exec_prefix is None:

Lib/site.py

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

364364
def addsitepackages(known_paths, prefixes=None):
365-
"""Add site-packages to sys.path"""
365+
"""Add site-packages to sys.path
366+
367+
'/usr/local' is included in PREFIXES if RPM build is not detected
368+
to make packages installed into this location visible.
369+
370+
"""
371+
if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ:
372+
PREFIXES.insert(0, "/usr/local")
366373
for sitedir in getsitepackages(prefixes):
367374
if os.path.isdir(sitedir):
368375
addsitedir(sitedir, known_paths)

Lib/sysconfig.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@
8686
},
8787
}
8888

89+
# Force pip to use distutils paths instead of sysconfig
90+
# https://github.com/pypa/pip/issues/10647
91+
_PIP_USE_SYSCONFIG = False
92+
93+
# This is used by distutils.command.install in the stdlib
94+
# as well as pypa/distutils (e.g. bundled in setuptools).
95+
# The self.prefix value is set to sys.prefix + /local/
96+
# if neither RPM build nor virtual environment is
97+
# detected to make distutils install packages
98+
# into the separate location.
99+
# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
100+
if (not (hasattr(sys, 'real_prefix') or
101+
sys.prefix != sys.base_prefix) and
102+
'RPM_BUILD_ROOT' not in os.environ):
103+
_prefix_addition = "/local"
104+
105+
89106
_SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
90107
'scripts', 'data')
91108

0 commit comments

Comments
 (0)