2020-08-05 16:46:46 +00:00
|
|
|
From 854fd7296bb9306d46ba3cc8bb7c6f18a7960ed6 Mon Sep 17 00:00:00 2001
|
2020-04-26 21:10:08 +00:00
|
|
|
From: Tomas Hrnciar <thrnciar@redhat.com>
|
|
|
|
Date: Sun, 26 Apr 2020 21:19:03 +0200
|
|
|
|
Subject: [PATCH] Prevent removing of the system packages installed under
|
|
|
|
/usr/lib
|
2018-08-30 13:27:55 +00:00
|
|
|
|
2019-11-12 16:31:50 +00:00
|
|
|
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>
|
2020-12-03 10:21:56 +00:00
|
|
|
Co-Authored-By: Petr Viktorin <pviktori@redhat.com>
|
2019-11-12 16:31:50 +00:00
|
|
|
---
|
2018-08-30 13:27:55 +00:00
|
|
|
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
|
2020-08-05 16:46:46 +00:00
|
|
|
index 4759f4a..2e76e35 100644
|
2018-08-30 13:27:55 +00:00
|
|
|
--- a/src/pip/_internal/req/req_install.py
|
|
|
|
+++ b/src/pip/_internal/req/req_install.py
|
2020-12-02 15:46:34 +00:00
|
|
|
@@ -41,6 +41,7 @@ from pip._internal.utils.misc import (
|
2019-11-12 16:31:50 +00:00
|
|
|
ask_path_exists,
|
|
|
|
backup_dir,
|
|
|
|
display_path,
|
|
|
|
+ dist_in_install_path,
|
|
|
|
dist_in_site_packages,
|
|
|
|
dist_in_usersite,
|
2020-08-05 16:46:46 +00:00
|
|
|
get_distribution,
|
2020-12-02 15:46:34 +00:00
|
|
|
@@ -447,7 +448,7 @@ class InstallRequirement(object):
|
2020-04-26 21:10:08 +00:00
|
|
|
"lack sys.path precedence to {} in {}".format(
|
|
|
|
existing_dist.project_name, existing_dist.location)
|
2018-08-30 13:27:55 +00:00
|
|
|
)
|
|
|
|
- else:
|
|
|
|
+ elif dist_in_install_path(existing_dist):
|
2020-03-04 11:20:06 +00:00
|
|
|
self.should_reinstall = True
|
|
|
|
else:
|
2020-08-05 16:46:46 +00:00
|
|
|
if self.editable:
|
2020-04-26 21:10:08 +00:00
|
|
|
diff --git a/src/pip/_internal/resolution/legacy/resolver.py b/src/pip/_internal/resolution/legacy/resolver.py
|
2020-08-05 16:46:46 +00:00
|
|
|
index c9b4c66..ff361d8 100644
|
2020-04-26 21:10:08 +00:00
|
|
|
--- a/src/pip/_internal/resolution/legacy/resolver.py
|
|
|
|
+++ b/src/pip/_internal/resolution/legacy/resolver.py
|
2020-08-05 16:46:46 +00:00
|
|
|
@@ -34,6 +34,7 @@ from pip._internal.resolution.base import BaseResolver
|
2020-04-26 21:10:08 +00:00
|
|
|
from pip._internal.utils.compatibility_tags import get_supported
|
|
|
|
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
|
2020-12-02 15:46:34 +00:00
|
|
|
from pip._internal.utils.packaging import check_requires_python, get_requires_python
|
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
|
|
|
|
|
|
|
@@ -204,7 +205,9 @@ class Resolver(BaseResolver):
|
2020-04-26 21:10:08 +00:00
|
|
|
"""
|
|
|
|
# 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
|
|
|
|
|
2018-08-30 13:27:55 +00:00
|
|
|
diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py
|
2020-08-05 16:46:46 +00:00
|
|
|
index 24a7455..5fd48d3 100644
|
2018-08-30 13:27:55 +00:00
|
|
|
--- a/src/pip/_internal/utils/misc.py
|
|
|
|
+++ b/src/pip/_internal/utils/misc.py
|
2020-12-02 15:46:34 +00:00
|
|
|
@@ -31,7 +31,7 @@ from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
|
|
|
|
|
2019-09-02 08:28:45 +00:00
|
|
|
from pip import __version__
|
2019-11-12 16:31:50 +00:00
|
|
|
from pip._internal.exceptions import CommandError
|
2020-12-02 15:46:34 +00:00
|
|
|
-from pip._internal.locations import get_major_minor_version, site_packages, user_site
|
|
|
|
+from pip._internal.locations import distutils_scheme, get_major_minor_version, site_packages, user_site
|
|
|
|
from pip._internal.utils.compat import WINDOWS, expanduser, stdlib_pkgs, str_to_display
|
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast
|
|
|
|
from pip._internal.utils.virtualenv import (
|
|
|
|
@@ -406,6 +406,16 @@ def dist_in_site_packages(dist):
|
2019-11-12 16:31:50 +00:00
|
|
|
return dist_location(dist).startswith(normalize_path(site_packages))
|
2018-08-30 13:27:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
+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):
|
2019-02-13 10:56:20 +00:00
|
|
|
# type: (Distribution) -> bool
|
|
|
|
"""
|
2020-12-03 10:21:56 +00:00
|
|
|
--- a/src/pip/_internal/resolution/resolvelib/factory.py
|
|
|
|
+++ b/src/pip/_internal/resolution/resolvelib/factory.py
|
|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
import logging
|
|
|
|
+import sys
|
|
|
|
|
|
|
|
from pip._vendor.packaging.utils import canonicalize_name
|
|
|
|
@@ -17,5 +18,7 @@
|
|
|
|
dist_in_usersite,
|
|
|
|
get_installed_distributions,
|
|
|
|
+ dist_location,
|
|
|
|
)
|
|
|
|
+from pip._internal.locations import distutils_scheme
|
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
|
|
|
from pip._internal.utils.virtualenv import running_under_virtualenv
|
|
|
|
@@ -313,4 +316,11 @@
|
|
|
|
return None
|
|
|
|
|
|
|
|
+ # Prevent uninstalling packages from /usr
|
|
|
|
+ if dist_location(dist) in (
|
|
|
|
+ distutils_scheme('', prefix=sys.base_prefix)['purelib'],
|
|
|
|
+ distutils_scheme('', prefix=sys.base_prefix)['platlib'],
|
|
|
|
+ ):
|
|
|
|
+ return None
|
|
|
|
+
|
|
|
|
# We're installing into global site. The current installation must
|
|
|
|
# be uninstalled, no matter it's in global or user site, because the
|
2019-11-12 16:31:50 +00:00
|
|
|
--
|
2020-08-05 16:46:46 +00:00
|
|
|
2.25.4
|
2019-11-12 16:31:50 +00:00
|
|
|
|