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

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