python-pip/remove-existing-dist-only-if-path-conflicts.patch
Miro Hrončok f994ff1cc7 Update to 20.0.2
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1793456

The main() wrapper moved the import path again, this time with compatibility shim:

 - we still need pip-allow-different-versions.patch to support older pips installed by users
 - we dropped callable-main.patch - the shim is provided by pip for all previous paths
 - no need to patch older pips to support user installed pip 20+
 - no need to patch Pythons (or virtualenv) to support pip 20+ wheel in ensurepip
2020-03-04 12:47:38 +01:00

95 lines
3.4 KiB
Diff

From b46ec3663c0535fc40503fe9a78b1b7733281bdf Mon Sep 17 00:00:00 2001
From: Tomas Orsava <torsava@redhat.com>
Date: Tue, 12 Nov 2019 17:24:20 +0100
Subject: [PATCH] Subject: Prevent removing of the system packages installed
under /usr/lib
when pip install -U is executed.
Resolves: rhbz#1550368
Co-Authored-By: Michal Cyprian <m.cyprian@gmail.com>
Co-Authored-By: Victor Stinner <vstinner@redhat.com>
---
src/pip/_internal/legacy_resolve.py | 5 ++++-
src/pip/_internal/req/req_install.py | 3 ++-
src/pip/_internal/utils/misc.py | 11 +++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/pip/_internal/legacy_resolve.py b/src/pip/_internal/legacy_resolve.py
index ca269121..e8d939bf 100644
--- a/src/pip/_internal/legacy_resolve.py
+++ b/src/pip/_internal/legacy_resolve.py
@@ -30,6 +30,7 @@ from pip._internal.exceptions import (
)
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import dist_in_usersite, normalize_version_info
+from pip._internal.utils.misc import dist_in_install_path
from pip._internal.utils.packaging import (
check_requires_python,
get_requires_python,
@@ -199,7 +200,9 @@ class Resolver(object):
"""
# Don't uninstall the conflict if doing a user install and the
# conflict is not a user install.
- if not self.use_user_site or dist_in_usersite(req.satisfied_by):
+ if ((not self.use_user_site
+ or dist_in_usersite(req.satisfied_by))
+ and dist_in_install_path(req.satisfied_by)):
req.should_reinstall = True
req.satisfied_by = None
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
index 22ac24b9..8a461b95 100644
--- a/src/pip/_internal/req/req_install.py
+++ b/src/pip/_internal/req/req_install.py
@@ -42,6 +42,7 @@ from pip._internal.utils.misc import (
ask_path_exists,
backup_dir,
display_path,
+ dist_in_install_path,
dist_in_site_packages,
dist_in_usersite,
get_installed_version,
@@ -457,7 +458,7 @@ class InstallRequirement(object):
"lack sys.path precedence to %s in %s" %
(existing_dist.project_name, existing_dist.location)
)
- else:
+ elif dist_in_install_path(existing_dist):
self.should_reinstall = True
else:
if self.editable and self.satisfied_by:
diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py
index 4a581601..2617ad33 100644
--- a/src/pip/_internal/utils/misc.py
+++ b/src/pip/_internal/utils/misc.py
@@ -29,6 +29,7 @@ from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
from pip import __version__
from pip._internal.exceptions import CommandError
from pip._internal.locations import (
+ distutils_scheme,
get_major_minor_version,
site_packages,
user_site,
@@ -385,6 +386,16 @@ def dist_in_site_packages(dist):
return dist_location(dist).startswith(normalize_path(site_packages))
+def dist_in_install_path(dist):
+ """
+ Return True if given Distribution is installed in
+ path matching distutils_scheme layout.
+ """
+ norm_path = normalize_path(dist_location(dist))
+ return norm_path.startswith(normalize_path(
+ distutils_scheme("")['purelib'].split('python')[0]))
+
+
def dist_is_editable(dist):
# type: (Distribution) -> bool
"""
--
2.24.1