orion / rpms / python3x-pip

Forked from rpms/python3x-pip 2 years ago
Clone

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

bcedfd
commit b6d5da6796801862eb751a93d507c343af0604d6
bcedfd
Author: Victor Stinner <vstinner@redhat.com>
bcedfd
Date:   Tue Sep 18 17:13:51 2018 +0200
bcedfd
bcedfd
    Subject: Prevent removing of the system packages installed under /usr/lib
bcedfd
    
bcedfd
    when pip install -U is executed.
bcedfd
    
bcedfd
    Resolves: rhbz#1550368
bcedfd
    
bcedfd
    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
bcedfd
index 1d9229cb..3088d22d 100644
bcedfd
--- a/src/pip/_internal/legacy_resolve.py
bcedfd
+++ b/src/pip/_internal/legacy_resolve.py
bcedfd
@@ -24,7 +24,7 @@ from pip._internal.exceptions import (
bcedfd
 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 (
bcedfd
-    dist_in_usersite, ensure_dir, normalize_version_info,
bcedfd
+    dist_in_install_path, dist_in_usersite, ensure_dir, normalize_version_info,
bcedfd
 )
bcedfd
 from pip._internal.utils.packaging import (
bcedfd
     check_requires_python, get_requires_python,
bcedfd
@@ -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
bcedfd
index f5c93504..1096c397 100644
bcedfd
--- a/src/pip/_internal/req/req_install.py
bcedfd
+++ b/src/pip/_internal/req/req_install.py
bcedfd
@@ -27,7 +27,7 @@ from pip._internal.utils.logging import indent_log
bcedfd
 from pip._internal.utils.marker_files import PIP_DELETE_MARKER_FILENAME
bcedfd
 from pip._internal.utils.misc import (
bcedfd
     _make_build_dir, ask_path_exists, backup_dir, call_subprocess,
bcedfd
-    display_path, dist_in_site_packages, dist_in_usersite, ensure_dir,
bcedfd
+    display_path, dist_in_install_path, dist_in_site_packages, dist_in_usersite, ensure_dir,
bcedfd
     get_installed_version, redact_password_from_url, rmtree,
bcedfd
 )
bcedfd
 from pip._internal.utils.packaging import get_metadata
bcedfd
@@ -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
bcedfd
index 61f74dc8..ffa8042c 100644
bcedfd
--- a/src/pip/_internal/utils/misc.py
bcedfd
+++ b/src/pip/_internal/utils/misc.py
bcedfd
@@ -30,7 +30,7 @@ from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
bcedfd
 
bcedfd
 from pip import __version__
bcedfd
 from pip._internal.exceptions import CommandError, InstallationError
bcedfd
-from pip._internal.locations import site_packages, user_site
bcedfd
+from pip._internal.locations import distutils_scheme, site_packages, user_site
bcedfd
 from pip._internal.utils.compat import (
bcedfd
     WINDOWS, console_to_str, expanduser, stdlib_pkgs, str_to_display,
bcedfd
 )
bcedfd
@@ -454,6 +454,16 @@ def dist_in_site_packages(dist):
bcedfd
     ).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
     """