churchyard / rpms / python38

Forked from rpms/python38 5 years ago
Clone
ec69e79
From 3e26b01573488b015065139689be3aa47dac17cf Mon Sep 17 00:00:00 2001
7fd9466
From: Michal Cyprian <m.cyprian@gmail.com>
7fd9466
Date: Mon, 26 Jun 2017 16:32:56 +0200
74db11e
Subject: [PATCH 5/7] 00251: Change user install location
7fd9466
7fd9466
Set values of prefix and exec_prefix in distutils install command
7fd9466
to /usr/local if executable is /usr/bin/python* and RPM build
7fd9466
is not detected to make pip and distutils install into separate location.
7fd9466
7fd9466
Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
7fd9466
---
7fd9466
 Lib/distutils/command/install.py | 15 +++++++++++++--
7fd9466
 Lib/site.py                      |  9 ++++++++-
7fd9466
 2 files changed, 21 insertions(+), 3 deletions(-)
7fd9466
332b947
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
7fd9466
index ae4f915669..0e4fd5b74a 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")
7fd9466
 
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
7fd9466
 
332b947
             else:
332b947
                 if self.exec_prefix is None:
332b947
diff --git a/Lib/site.py b/Lib/site.py
ec69e79
index 22d53fa562..9513526109 100644
332b947
--- a/Lib/site.py
332b947
+++ b/Lib/site.py
ec69e79
@@ -348,7 +348,14 @@ def getsitepackages(prefixes=None):
332b947
     return sitepackages
7fd9466
 
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)
7fd9466
-- 
7fd9466
2.21.0
7fd9466