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

93a1c0
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
93a1c0
From: Michal Cyprian <m.cyprian@gmail.com>
93a1c0
Date: Mon, 26 Jun 2017 16:32:56 +0200
93a1c0
Subject: [PATCH] 00251: Change user install location
93a1c0
93a1c0
Set values of prefix and exec_prefix in distutils install command
93a1c0
to /usr/local if executable is /usr/bin/python* and RPM build
93a1c0
is not detected to make pip and distutils install into separate location.
93a1c0
93a1c0
Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
93a1c0
Downstream only: Awaiting resources to work on upstream PEP
93a1c0
---
93a1c0
 Lib/distutils/command/install.py | 15 +++++++++++++--
93a1c0
 Lib/site.py                      |  9 ++++++++-
93a1c0
 2 files changed, 21 insertions(+), 3 deletions(-)
93a1c0
93a1c0
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
93a1c0
index aaa300efa9..f8d453912a 100644
93a1c0
--- a/Lib/distutils/command/install.py
93a1c0
+++ b/Lib/distutils/command/install.py
93a1c0
@@ -419,8 +419,19 @@ class install(Command):
93a1c0
                     raise DistutilsOptionError(
93a1c0
                           "must not supply exec-prefix without prefix")
93a1c0
 
93a1c0
-                self.prefix = os.path.normpath(sys.prefix)
93a1c0
-                self.exec_prefix = os.path.normpath(sys.exec_prefix)
93a1c0
+                # self.prefix is set to sys.prefix + /local/
93a1c0
+                # if neither RPM build nor virtual environment is
93a1c0
+                # detected to make pip and distutils install packages
93a1c0
+                # into the separate location.
93a1c0
+                if (not (hasattr(sys, 'real_prefix') or
93a1c0
+                    sys.prefix != sys.base_prefix) and
93a1c0
+                    'RPM_BUILD_ROOT' not in os.environ):
93a1c0
+                    addition = "/local"
93a1c0
+                else:
93a1c0
+                    addition = ""
93a1c0
+
93a1c0
+                self.prefix = os.path.normpath(sys.prefix) + addition
93a1c0
+                self.exec_prefix = os.path.normpath(sys.exec_prefix) + addition
93a1c0
 
93a1c0
             else:
93a1c0
                 if self.exec_prefix is None:
93a1c0
diff --git a/Lib/site.py b/Lib/site.py
93a1c0
index 9e617afb00..db14f715f9 100644
93a1c0
--- a/Lib/site.py
93a1c0
+++ b/Lib/site.py
93a1c0
@@ -353,7 +353,14 @@ def getsitepackages(prefixes=None):
93a1c0
     return sitepackages
93a1c0
 
93a1c0
 def addsitepackages(known_paths, prefixes=None):
93a1c0
-    """Add site-packages to sys.path"""
93a1c0
+    """Add site-packages to sys.path
93a1c0
+
93a1c0
+    '/usr/local' is included in PREFIXES if RPM build is not detected
93a1c0
+    to make packages installed into this location visible.
93a1c0
+
93a1c0
+    """
93a1c0
+    if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ:
93a1c0
+        PREFIXES.insert(0, "/usr/local")
93a1c0
     for sitedir in getsitepackages(prefixes):
93a1c0
         if os.path.isdir(sitedir):
93a1c0
             addsitedir(sitedir, known_paths)