churchyard / rpms / python3

Forked from rpms/python3 3 years ago
Clone

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

332b947
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
332b947
index 9d31d13..ed44a93 100644
332b947
--- a/Lib/distutils/command/install.py
332b947
+++ b/Lib/distutils/command/install.py
332b947
@@ -424,8 +424,18 @@ class install(Command):
332b947
                     raise DistutilsOptionError(
332b947
                           "must not supply exec-prefix without prefix")
332b947
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/
332b947
+                # if the executable is /usr/bin/python* and RPM build
332b947
+                # is not detected to make pip and distutils install into
332b947
+                # the separate location.
332b947
+                if (sys.executable.startswith("/usr/bin/python")
332b947
+                    and '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
332b947
332b947
             else:
332b947
                 if self.exec_prefix is None:
332b947
diff --git a/Lib/site.py b/Lib/site.py
332b947
index 4744eb0..b5fe571 100644
332b947
--- a/Lib/site.py
332b947
+++ b/Lib/site.py
332b947
@@ -326,7 +326,15 @@ def getsitepackages(prefixes=None):
332b947
     return sitepackages
332b947
332b947
 def addsitepackages(known_paths, prefixes=None):
332b947
-    """Add site-packages to sys.path"""
332b947
+    """Add site-packages to sys.path.
332b947
+
332b947
+    '/usr/local' is included in PREFIXES if the executable is /usr/bin/python*
332b947
+    and RPM build is not detected to make sudo pip installed packages visible.
332b947
+
332b947
+    """
332b947
+    if (ENABLE_USER_SITE and sys.executable.startswith("/usr/bin/python")
332b947
+        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)