lbalhar / rpms / python3.7

Forked from rpms/python3.7 3 years ago
Clone

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

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