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

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