churchyard / rpms / python3

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