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

e4c486
From 8c58a99221415ca7c3d5ce50dcffefa14e421928 Mon Sep 17 00:00:00 2001
e4c486
From: Tomas Orsava <torsava@redhat.com>
e4c486
Date: Tue, 12 Nov 2019 17:24:20 +0100
e4c486
Subject: [PATCH] Subject: Prevent removing of the system packages installed
e4c486
 under /usr/lib
e4c486
e4c486
when pip install -U is executed.
e4c486
e4c486
Resolves: rhbz#1550368
e4c486
e4c486
Co-Authored-By: Michal Cyprian <m.cyprian@gmail.com>
e4c486
Co-Authored-By: Victor Stinner <vstinner@redhat.com>
e4c486
---
e4c486
 src/pip/_internal/legacy_resolve.py  |  5 ++++-
e4c486
 src/pip/_internal/req/req_install.py |  3 ++-
e4c486
 src/pip/_internal/utils/misc.py      | 11 +++++++++++
e4c486
 3 files changed, 17 insertions(+), 2 deletions(-)
e4c486
e4c486
diff --git a/src/pip/_internal/legacy_resolve.py b/src/pip/_internal/legacy_resolve.py
e4c486
index c24158f..bd92287 100644
e4c486
--- a/src/pip/_internal/legacy_resolve.py
e4c486
+++ b/src/pip/_internal/legacy_resolve.py
e4c486
@@ -30,6 +30,7 @@ from pip._internal.exceptions import (
e4c486
 )
e4c486
 from pip._internal.utils.logging import indent_log
e4c486
 from pip._internal.utils.misc import (
e4c486
+    dist_in_install_path,
e4c486
     dist_in_usersite,
e4c486
     ensure_dir,
e4c486
     normalize_version_info,
e4c486
@@ -224,7 +225,9 @@ class Resolver(object):
e4c486
         """
e4c486
         # Don't uninstall the conflict if doing a user install and the
e4c486
         # conflict is not a user install.
e4c486
-        if not self.use_user_site or dist_in_usersite(req.satisfied_by):
e4c486
+        if ((not self.use_user_site
e4c486
+                or dist_in_usersite(req.satisfied_by))
e4c486
+                and dist_in_install_path(req.satisfied_by)):
e4c486
             req.conflicts_with = req.satisfied_by
e4c486
         req.satisfied_by = None
e4c486
 
e4c486
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
e4c486
index 5a8c0dc..f80ba87 100644
e4c486
--- a/src/pip/_internal/req/req_install.py
e4c486
+++ b/src/pip/_internal/req/req_install.py
e4c486
@@ -39,6 +39,7 @@ from pip._internal.utils.misc import (
e4c486
     ask_path_exists,
e4c486
     backup_dir,
e4c486
     display_path,
e4c486
+    dist_in_install_path,
e4c486
     dist_in_site_packages,
e4c486
     dist_in_usersite,
e4c486
     ensure_dir,
e4c486
@@ -461,7 +462,7 @@ class InstallRequirement(object):
e4c486
                         "lack sys.path precedence to %s in %s" %
e4c486
                         (existing_dist.project_name, existing_dist.location)
e4c486
                     )
e4c486
-            else:
e4c486
+            elif dist_in_install_path(existing_dist):
e4c486
                 self.conflicts_with = existing_dist
e4c486
         return True
e4c486
 
e4c486
diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py
e4c486
index b848263..5b75fed 100644
e4c486
--- a/src/pip/_internal/utils/misc.py
e4c486
+++ b/src/pip/_internal/utils/misc.py
e4c486
@@ -28,6 +28,7 @@ from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
e4c486
 from pip import __version__
e4c486
 from pip._internal.exceptions import CommandError
e4c486
 from pip._internal.locations import (
e4c486
+    distutils_scheme,
e4c486
     get_major_minor_version,
e4c486
     site_packages,
e4c486
     user_site,
e4c486
@@ -389,6 +390,16 @@ def dist_in_site_packages(dist):
e4c486
     return dist_location(dist).startswith(normalize_path(site_packages))
e4c486
 
e4c486
 
e4c486
+def dist_in_install_path(dist):
e4c486
+    """
e4c486
+    Return True if given Distribution is installed in
e4c486
+    path matching distutils_scheme layout.
e4c486
+    """
e4c486
+    norm_path = normalize_path(dist_location(dist))
e4c486
+    return norm_path.startswith(normalize_path(
e4c486
+        distutils_scheme("")['purelib'].split('python')[0]))
e4c486
+
e4c486
+
e4c486
 def dist_is_editable(dist):
e4c486
     # type: (Distribution) -> bool
e4c486
     """
e4c486
-- 
e4c486
2.20.1
e4c486