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

313c88
From 8c58a99221415ca7c3d5ce50dcffefa14e421928 Mon Sep 17 00:00:00 2001
313c88
From: Tomas Orsava <torsava@redhat.com>
313c88
Date: Tue, 12 Nov 2019 17:24:20 +0100
313c88
Subject: [PATCH] Subject: Prevent removing of the system packages installed
313c88
 under /usr/lib
bcedfd
313c88
when pip install -U is executed.
313c88
313c88
Resolves: rhbz#1550368
313c88
313c88
Co-Authored-By: Michal Cyprian <m.cyprian@gmail.com>
313c88
Co-Authored-By: Victor Stinner <vstinner@redhat.com>
313c88
---
313c88
 src/pip/_internal/legacy_resolve.py  |  5 ++++-
313c88
 src/pip/_internal/req/req_install.py |  3 ++-
313c88
 src/pip/_internal/utils/misc.py      | 11 +++++++++++
313c88
 3 files changed, 17 insertions(+), 2 deletions(-)
bcedfd
bcedfd
diff --git a/src/pip/_internal/legacy_resolve.py b/src/pip/_internal/legacy_resolve.py
313c88
index c24158f..bd92287 100644
bcedfd
--- a/src/pip/_internal/legacy_resolve.py
bcedfd
+++ b/src/pip/_internal/legacy_resolve.py
313c88
@@ -30,6 +30,7 @@ from pip._internal.exceptions import (
313c88
 )
bcedfd
 from pip._internal.utils.logging import indent_log
bcedfd
 from pip._internal.utils.misc import (
313c88
+    dist_in_install_path,
313c88
     dist_in_usersite,
313c88
     ensure_dir,
313c88
     normalize_version_info,
313c88
@@ -224,7 +225,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
313c88
index 5a8c0dc..f80ba87 100644
bcedfd
--- a/src/pip/_internal/req/req_install.py
bcedfd
+++ b/src/pip/_internal/req/req_install.py
313c88
@@ -39,6 +39,7 @@ from pip._internal.utils.misc import (
313c88
     ask_path_exists,
313c88
     backup_dir,
313c88
     display_path,
313c88
+    dist_in_install_path,
313c88
     dist_in_site_packages,
313c88
     dist_in_usersite,
313c88
     ensure_dir,
313c88
@@ -461,7 +462,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
313c88
index b848263..5b75fed 100644
bcedfd
--- a/src/pip/_internal/utils/misc.py
bcedfd
+++ b/src/pip/_internal/utils/misc.py
313c88
@@ -28,6 +28,7 @@ from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
bcedfd
 from pip import __version__
313c88
 from pip._internal.exceptions import CommandError
313c88
 from pip._internal.locations import (
313c88
+    distutils_scheme,
313c88
     get_major_minor_version,
313c88
     site_packages,
313c88
     user_site,
313c88
@@ -389,6 +390,16 @@ def dist_in_site_packages(dist):
313c88
     return dist_location(dist).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
     """
313c88
-- 
313c88
2.20.1
313c88