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