2021-02-18 16:32:30 +00:00
|
|
|
From f83eacf40f1506418e74d747906b8f108401f91d Mon Sep 17 00:00:00 2001
|
2021-01-27 11:42:40 +00:00
|
|
|
From: Lumir Balhar <lbalhar@redhat.com>
|
|
|
|
Date: Tue, 26 Jan 2021 09:05:07 +0100
|
2021-02-18 16:32:30 +00:00
|
|
|
Subject: [PATCH] Prevent removing of the system packages installed under
|
2020-10-15 02:37:16 +00:00
|
|
|
/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>
|
2020-12-19 00:15:05 +00:00
|
|
|
Co-Authored-By: Petr Viktorin <pviktori@redhat.com>
|
2020-10-15 02:37:16 +00:00
|
|
|
---
|
2021-01-27 11:42:40 +00:00
|
|
|
src/pip/_internal/req/req_install.py | 3 ++-
|
|
|
|
src/pip/_internal/resolution/legacy/resolver.py | 5 ++++-
|
|
|
|
src/pip/_internal/resolution/resolvelib/factory.py | 10 ++++++++++
|
|
|
|
src/pip/_internal/utils/misc.py | 11 +++++++++++
|
|
|
|
4 files changed, 27 insertions(+), 2 deletions(-)
|
|
|
|
|
2020-10-15 02:37:16 +00:00
|
|
|
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
|
2021-01-27 11:42:40 +00:00
|
|
|
index 6d0aa30..0a5f8ed 100644
|
2020-10-15 02:37:16 +00:00
|
|
|
--- a/src/pip/_internal/req/req_install.py
|
|
|
|
+++ b/src/pip/_internal/req/req_install.py
|
2021-01-27 11:42:40 +00:00
|
|
|
@@ -39,6 +39,7 @@ from pip._internal.utils.misc import (
|
2020-10-15 02:37:16 +00:00
|
|
|
ask_path_exists,
|
|
|
|
backup_dir,
|
|
|
|
display_path,
|
|
|
|
+ dist_in_install_path,
|
|
|
|
dist_in_site_packages,
|
|
|
|
dist_in_usersite,
|
|
|
|
get_distribution,
|
2021-01-27 11:42:40 +00:00
|
|
|
@@ -445,7 +446,7 @@ class InstallRequirement:
|
2020-10-15 02:37:16 +00:00
|
|
|
"lack sys.path precedence to {} in {}".format(
|
|
|
|
existing_dist.project_name, existing_dist.location)
|
|
|
|
)
|
|
|
|
- else:
|
|
|
|
+ elif dist_in_install_path(existing_dist):
|
|
|
|
self.should_reinstall = True
|
|
|
|
else:
|
|
|
|
if self.editable:
|
|
|
|
diff --git a/src/pip/_internal/resolution/legacy/resolver.py b/src/pip/_internal/resolution/legacy/resolver.py
|
2021-01-27 11:42:40 +00:00
|
|
|
index 665dba1..a219e63 100644
|
2020-10-15 02:37:16 +00:00
|
|
|
--- a/src/pip/_internal/resolution/legacy/resolver.py
|
|
|
|
+++ b/src/pip/_internal/resolution/legacy/resolver.py
|
|
|
|
@@ -34,6 +34,7 @@ from pip._internal.resolution.base import BaseResolver
|
|
|
|
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-19 00:15:05 +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-10-15 02:37:16 +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
|
|
|
|
|
2021-01-27 11:42:40 +00:00
|
|
|
diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py
|
2021-02-18 16:32:30 +00:00
|
|
|
index be0729e..bc2912b 100644
|
2020-12-19 00:15:05 +00:00
|
|
|
--- a/src/pip/_internal/resolution/resolvelib/factory.py
|
|
|
|
+++ b/src/pip/_internal/resolution/resolvelib/factory.py
|
2021-02-18 16:32:30 +00:00
|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
import functools
|
2020-12-19 00:15:05 +00:00
|
|
|
import logging
|
|
|
|
+import sys
|
|
|
|
|
|
|
|
from pip._vendor.packaging.utils import canonicalize_name
|
2021-01-27 11:42:40 +00:00
|
|
|
|
2021-02-18 16:32:30 +00:00
|
|
|
@@ -19,7 +20,9 @@ from pip._internal.utils.misc import (
|
2021-01-27 11:42:40 +00:00
|
|
|
dist_in_site_packages,
|
2020-12-19 00:15:05 +00:00
|
|
|
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
|
2021-01-27 11:42:40 +00:00
|
|
|
|
2021-02-18 16:32:30 +00:00
|
|
|
@@ -362,6 +365,13 @@ class Factory:
|
2021-01-27 11:42:40 +00:00
|
|
|
if dist is None: # Not installed, no uninstallation required.
|
2020-12-19 00:15:05 +00:00
|
|
|
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
|
2021-01-27 11:42:40 +00:00
|
|
|
# user site installation has precedence over global.
|
|
|
|
diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py
|
|
|
|
index 6dd94e2..7925518 100644
|
|
|
|
--- a/src/pip/_internal/utils/misc.py
|
|
|
|
+++ b/src/pip/_internal/utils/misc.py
|
|
|
|
@@ -27,6 +27,7 @@ from pip._vendor.retrying import retry # type: ignore
|
|
|
|
from pip import __version__
|
|
|
|
from pip._internal.exceptions import CommandError
|
|
|
|
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, stdlib_pkgs
|
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast
|
|
|
|
from pip._internal.utils.virtualenv import (
|
|
|
|
@@ -398,6 +399,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
|
|
|
|
"""
|
2020-10-15 02:37:16 +00:00
|
|
|
--
|
2021-01-27 11:42:40 +00:00
|
|
|
2.29.2
|
2020-10-15 02:37:16 +00:00
|
|
|
|