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

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