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

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