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

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