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

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