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