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

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