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

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