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

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