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

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