orion / rpms / python3x-pip

Forked from rpms/python3x-pip 2 years ago
Clone

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

d00c25
From 854fd7296bb9306d46ba3cc8bb7c6f18a7960ed6 Mon Sep 17 00:00:00 2001
d00c25
From: Tomas Hrnciar <thrnciar@redhat.com>
d00c25
Date: Sun, 26 Apr 2020 21:19:03 +0200
d00c25
Subject: [PATCH] Prevent removing of the system packages installed under
d00c25
 /usr/lib
d00c25
d00c25
when pip install -U is executed.
d00c25
d00c25
Resolves: rhbz#1550368
d00c25
d00c25
Co-Authored-By: Michal Cyprian <m.cyprian@gmail.com>
d00c25
Co-Authored-By: Victor Stinner <vstinner@redhat.com>
d00c25
---
d00c25
 src/pip/_internal/req/req_install.py            |  3 ++-
d00c25
 src/pip/_internal/resolution/legacy/resolver.py |  5 ++++-
d00c25
 src/pip/_internal/utils/misc.py                 | 11 +++++++++++
d00c25
 3 files changed, 17 insertions(+), 2 deletions(-)
d00c25
d00c25
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
d00c25
index 4759f4a..2e76e35 100644
d00c25
--- a/src/pip/_internal/req/req_install.py
d00c25
+++ b/src/pip/_internal/req/req_install.py
d00c25
@@ -39,6 +39,7 @@ from pip._internal.utils.misc import (
d00c25
     ask_path_exists,
d00c25
     backup_dir,
d00c25
     display_path,
d00c25
+    dist_in_install_path,
d00c25
     dist_in_site_packages,
d00c25
     dist_in_usersite,
d00c25
     get_distribution,
d00c25
@@ -446,7 +447,7 @@ class InstallRequirement(object):
d00c25
                         "lack sys.path precedence to {} in {}".format(
d00c25
                             existing_dist.project_name, existing_dist.location)
d00c25
                     )
d00c25
-            else:
d00c25
+            elif dist_in_install_path(existing_dist):
d00c25
                 self.should_reinstall = True
d00c25
         else:
d00c25
             if self.editable:
d00c25
diff --git a/src/pip/_internal/resolution/legacy/resolver.py b/src/pip/_internal/resolution/legacy/resolver.py
d00c25
index c9b4c66..ff361d8 100644
d00c25
--- a/src/pip/_internal/resolution/legacy/resolver.py
d00c25
+++ b/src/pip/_internal/resolution/legacy/resolver.py
d00c25
@@ -34,6 +34,7 @@ from pip._internal.resolution.base import BaseResolver
d00c25
 from pip._internal.utils.compatibility_tags import get_supported
d00c25
 from pip._internal.utils.logging import indent_log
d00c25
 from pip._internal.utils.misc import dist_in_usersite, normalize_version_info
d00c25
+from pip._internal.utils.misc import dist_in_install_path
d00c25
 from pip._internal.utils.packaging import (
d00c25
     check_requires_python,
d00c25
     get_requires_python,
d00c25
@@ -207,7 +208,9 @@ class Resolver(BaseResolver):
d00c25
         """
d00c25
         # Don't uninstall the conflict if doing a user install and the
d00c25
         # conflict is not a user install.
d00c25
-        if not self.use_user_site or dist_in_usersite(req.satisfied_by):
d00c25
+        if ((not self.use_user_site
d00c25
+                or dist_in_usersite(req.satisfied_by))
d00c25
+                and dist_in_install_path(req.satisfied_by)):
d00c25
             req.should_reinstall = True
d00c25
         req.satisfied_by = None
d00c25
 
d00c25
diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py
d00c25
index 24a7455..5fd48d3 100644
d00c25
--- a/src/pip/_internal/utils/misc.py
d00c25
+++ b/src/pip/_internal/utils/misc.py
d00c25
@@ -31,6 +31,7 @@ from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
d00c25
 from pip import __version__
d00c25
 from pip._internal.exceptions import CommandError
d00c25
 from pip._internal.locations import (
d00c25
+    distutils_scheme,
d00c25
     get_major_minor_version,
d00c25
     site_packages,
d00c25
     user_site,
d00c25
@@ -403,6 +404,16 @@ def dist_in_site_packages(dist):
d00c25
     return dist_location(dist).startswith(normalize_path(site_packages))
d00c25
 
d00c25
 
d00c25
+def dist_in_install_path(dist):
d00c25
+    """
d00c25
+    Return True if given Distribution is installed in
d00c25
+    path matching distutils_scheme layout.
d00c25
+    """
d00c25
+    norm_path = normalize_path(dist_location(dist))
d00c25
+    return norm_path.startswith(normalize_path(
d00c25
+        distutils_scheme("")['purelib'].split('python')[0]))
d00c25
+
d00c25
+
d00c25
 def dist_is_editable(dist):
d00c25
     # type: (Distribution) -> bool
d00c25
     """
d00c25
-- 
d00c25
2.25.4
d00c25