|
|
d71d1f |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
d71d1f |
From: Michal Cyprian <m.cyprian@gmail.com>
|
|
|
d71d1f |
Date: Mon, 26 Jun 2017 16:32:56 +0200
|
|
|
d71d1f |
Subject: [PATCH] 00251: Change user install location
|
|
|
d845c8 |
MIME-Version: 1.0
|
|
|
d845c8 |
Content-Type: text/plain; charset=UTF-8
|
|
|
d845c8 |
Content-Transfer-Encoding: 8bit
|
|
|
d71d1f |
|
|
|
d71d1f |
Set values of prefix and exec_prefix in distutils install command
|
|
|
d71d1f |
to /usr/local if executable is /usr/bin/python* and RPM build
|
|
|
d71d1f |
is not detected to make pip and distutils install into separate location.
|
|
|
d71d1f |
|
|
|
d71d1f |
Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
|
|
d845c8 |
Downstream only: Reworked in Fedora 36+/Python 3.10+ to follow https://bugs.python.org/issue43976
|
|
|
d845c8 |
|
|
|
d845c8 |
pypa/distutils integration: https://github.com/pypa/distutils/pull/70
|
|
|
d845c8 |
|
|
|
d845c8 |
Also set sysconfig._PIP_USE_SYSCONFIG = False, to force pip-upgraded-pip
|
|
|
d845c8 |
to respect this patched distutils install command.
|
|
|
d845c8 |
See https://bugzilla.redhat.com/show_bug.cgi?id=2014513
|
|
|
d845c8 |
|
|
|
d845c8 |
Co-authored-by: Miro HronĨok <miro@hroncok.cz>
|
|
|
d71d1f |
---
|
|
|
d845c8 |
Lib/distutils/command/install.py | 9 +++++++--
|
|
|
d71d1f |
Lib/site.py | 9 ++++++++-
|
|
|
d845c8 |
Lib/sysconfig.py | 17 +++++++++++++++++
|
|
|
d845c8 |
3 files changed, 32 insertions(+), 3 deletions(-)
|
|
|
d71d1f |
|
|
|
d71d1f |
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
|
|
|
d845c8 |
index aaa300efa9..18f01f10d4 100644
|
|
|
d71d1f |
--- a/Lib/distutils/command/install.py
|
|
|
d71d1f |
+++ b/Lib/distutils/command/install.py
|
|
|
d845c8 |
@@ -3,6 +3,7 @@
|
|
|
d845c8 |
Implements the Distutils 'install' command."""
|
|
|
d845c8 |
|
|
|
d845c8 |
import sys
|
|
|
d845c8 |
+import sysconfig
|
|
|
d845c8 |
import os
|
|
|
d845c8 |
|
|
|
d845c8 |
from distutils import log
|
|
|
d845c8 |
@@ -142,6 +143,8 @@ class install(Command):
|
|
|
d845c8 |
|
|
|
d845c8 |
negative_opt = {'no-compile' : 'compile'}
|
|
|
d845c8 |
|
|
|
d845c8 |
+ # Allow Fedora to add components to the prefix
|
|
|
d845c8 |
+ _prefix_addition = getattr(sysconfig, '_prefix_addition', '')
|
|
|
d845c8 |
|
|
|
d845c8 |
def initialize_options(self):
|
|
|
d845c8 |
"""Initializes options."""
|
|
|
d845c8 |
@@ -419,8 +422,10 @@ class install(Command):
|
|
|
d71d1f |
raise DistutilsOptionError(
|
|
|
d71d1f |
"must not supply exec-prefix without prefix")
|
|
|
d71d1f |
|
|
|
d71d1f |
- self.prefix = os.path.normpath(sys.prefix)
|
|
|
d71d1f |
- self.exec_prefix = os.path.normpath(sys.exec_prefix)
|
|
|
d845c8 |
+ self.prefix = (
|
|
|
d845c8 |
+ os.path.normpath(sys.prefix) + self._prefix_addition)
|
|
|
d845c8 |
+ self.exec_prefix = (
|
|
|
d845c8 |
+ os.path.normpath(sys.exec_prefix) + self._prefix_addition)
|
|
|
d71d1f |
|
|
|
d71d1f |
else:
|
|
|
d71d1f |
if self.exec_prefix is None:
|
|
|
d71d1f |
diff --git a/Lib/site.py b/Lib/site.py
|
|
|
d71d1f |
index 9e617afb00..db14f715f9 100644
|
|
|
d71d1f |
--- a/Lib/site.py
|
|
|
d71d1f |
+++ b/Lib/site.py
|
|
|
d71d1f |
@@ -353,7 +353,14 @@ def getsitepackages(prefixes=None):
|
|
|
d71d1f |
return sitepackages
|
|
|
d71d1f |
|
|
|
d71d1f |
def addsitepackages(known_paths, prefixes=None):
|
|
|
d71d1f |
- """Add site-packages to sys.path"""
|
|
|
d71d1f |
+ """Add site-packages to sys.path
|
|
|
d71d1f |
+
|
|
|
d71d1f |
+ '/usr/local' is included in PREFIXES if RPM build is not detected
|
|
|
d71d1f |
+ to make packages installed into this location visible.
|
|
|
d71d1f |
+
|
|
|
d71d1f |
+ """
|
|
|
d71d1f |
+ if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ:
|
|
|
d71d1f |
+ PREFIXES.insert(0, "/usr/local")
|
|
|
d71d1f |
for sitedir in getsitepackages(prefixes):
|
|
|
d71d1f |
if os.path.isdir(sitedir):
|
|
|
d71d1f |
addsitedir(sitedir, known_paths)
|
|
|
d845c8 |
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
|
|
|
d845c8 |
index e3f79bfde5..e124104876 100644
|
|
|
d845c8 |
--- a/Lib/sysconfig.py
|
|
|
d845c8 |
+++ b/Lib/sysconfig.py
|
|
|
d845c8 |
@@ -86,6 +86,23 @@ _INSTALL_SCHEMES = {
|
|
|
d845c8 |
},
|
|
|
d845c8 |
}
|
|
|
d845c8 |
|
|
|
d845c8 |
+# Force pip to use distutils paths instead of sysconfig
|
|
|
d845c8 |
+# https://github.com/pypa/pip/issues/10647
|
|
|
d845c8 |
+_PIP_USE_SYSCONFIG = False
|
|
|
d845c8 |
+
|
|
|
d845c8 |
+# This is used by distutils.command.install in the stdlib
|
|
|
d845c8 |
+# as well as pypa/distutils (e.g. bundled in setuptools).
|
|
|
d845c8 |
+# The self.prefix value is set to sys.prefix + /local/
|
|
|
d845c8 |
+# if neither RPM build nor virtual environment is
|
|
|
d845c8 |
+# detected to make distutils install packages
|
|
|
d845c8 |
+# into the separate location.
|
|
|
d845c8 |
+# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
|
|
d845c8 |
+if (not (hasattr(sys, 'real_prefix') or
|
|
|
d845c8 |
+ sys.prefix != sys.base_prefix) and
|
|
|
d845c8 |
+ 'RPM_BUILD_ROOT' not in os.environ):
|
|
|
d845c8 |
+ _prefix_addition = "/local"
|
|
|
d845c8 |
+
|
|
|
d845c8 |
+
|
|
|
d845c8 |
_SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
|
|
|
d845c8 |
'scripts', 'data')
|
|
|
d845c8 |
|