Blame 00251-change-user-install-location.patch

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