orion / rpms / python3x-pip

Forked from rpms/python3x-pip 2 years ago
Clone

Blame SOURCES/remove-existing-dist-only-if-path-conflicts.patch

000643
commit b6d5da6796801862eb751a93d507c343af0604d6
000643
Author: Victor Stinner <vstinner@redhat.com>
000643
Date:   Tue Sep 18 17:13:51 2018 +0200
bcedfd
000643
    Subject: Prevent removing of the system packages installed under /usr/lib
000643
    
000643
    when pip install -U is executed.
000643
    
000643
    Resolves: rhbz#1550368
000643
    
000643
    Co-Authored-By: Michal Cyprian <m.cyprian@gmail.com>
bcedfd
bcedfd
diff --git a/src/pip/_internal/legacy_resolve.py b/src/pip/_internal/legacy_resolve.py
000643
index 1d9229cb..3088d22d 100644
bcedfd
--- a/src/pip/_internal/legacy_resolve.py
bcedfd
+++ b/src/pip/_internal/legacy_resolve.py
000643
@@ -24,7 +24,7 @@ from pip._internal.exceptions import (
000643
 from pip._internal.req.constructors import install_req_from_req_string
bcedfd
 from pip._internal.utils.logging import indent_log
bcedfd
 from pip._internal.utils.misc import (
000643
-    dist_in_usersite, ensure_dir, normalize_version_info,
000643
+    dist_in_install_path, dist_in_usersite, ensure_dir, normalize_version_info,
000643
 )
000643
 from pip._internal.utils.packaging import (
000643
     check_requires_python, get_requires_python,
000643
@@ -219,7 +219,9 @@ class Resolver(object):
bcedfd
         """
bcedfd
         # Don't uninstall the conflict if doing a user install and the
bcedfd
         # conflict is not a user install.
bcedfd
-        if not self.use_user_site or dist_in_usersite(req.satisfied_by):
bcedfd
+        if ((not self.use_user_site
bcedfd
+                or dist_in_usersite(req.satisfied_by))
bcedfd
+                and dist_in_install_path(req.satisfied_by)):
bcedfd
             req.conflicts_with = req.satisfied_by
bcedfd
         req.satisfied_by = None
bcedfd
 
bcedfd
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
000643
index f5c93504..1096c397 100644
bcedfd
--- a/src/pip/_internal/req/req_install.py
bcedfd
+++ b/src/pip/_internal/req/req_install.py
000643
@@ -27,7 +27,7 @@ from pip._internal.utils.logging import indent_log
000643
 from pip._internal.utils.marker_files import PIP_DELETE_MARKER_FILENAME
000643
 from pip._internal.utils.misc import (
000643
     _make_build_dir, ask_path_exists, backup_dir, call_subprocess,
000643
-    display_path, dist_in_site_packages, dist_in_usersite, ensure_dir,
000643
+    display_path, dist_in_install_path, dist_in_site_packages, dist_in_usersite, ensure_dir,
000643
     get_installed_version, redact_password_from_url, rmtree,
000643
 )
000643
 from pip._internal.utils.packaging import get_metadata
000643
@@ -427,7 +427,7 @@ class InstallRequirement(object):
bcedfd
                         "lack sys.path precedence to %s in %s" %
bcedfd
                         (existing_dist.project_name, existing_dist.location)
bcedfd
                     )
bcedfd
-            else:
bcedfd
+            elif dist_in_install_path(existing_dist):
bcedfd
                 self.conflicts_with = existing_dist
bcedfd
         return True
bcedfd
 
bcedfd
diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py
000643
index 61f74dc8..ffa8042c 100644
bcedfd
--- a/src/pip/_internal/utils/misc.py
bcedfd
+++ b/src/pip/_internal/utils/misc.py
000643
@@ -30,7 +30,7 @@ from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
000643
 
bcedfd
 from pip import __version__
000643
 from pip._internal.exceptions import CommandError, InstallationError
000643
-from pip._internal.locations import site_packages, user_site
000643
+from pip._internal.locations import distutils_scheme, site_packages, user_site
000643
 from pip._internal.utils.compat import (
000643
     WINDOWS, console_to_str, expanduser, stdlib_pkgs, str_to_display,
000643
 )
000643
@@ -454,6 +454,16 @@ def dist_in_site_packages(dist):
000643
     ).startswith(normalize_path(site_packages))
bcedfd
 
bcedfd
 
bcedfd
+def dist_in_install_path(dist):
bcedfd
+    """
bcedfd
+    Return True if given Distribution is installed in
bcedfd
+    path matching distutils_scheme layout.
bcedfd
+    """
bcedfd
+    norm_path = normalize_path(dist_location(dist))
bcedfd
+    return norm_path.startswith(normalize_path(
bcedfd
+        distutils_scheme("")['purelib'].split('python')[0]))
bcedfd
+
bcedfd
+
bcedfd
 def dist_is_editable(dist):
bcedfd
     # type: (Distribution) -> bool
bcedfd
     """