2021-08-16 10:26:06 +00:00
|
|
|
From aca0c9df4ef54f70a3fedb07f4faac463f88a331 Mon Sep 17 00:00:00 2001
|
2021-05-11 14:58:03 +00:00
|
|
|
From: Karolina Surma <ksurma@redhat.com>
|
|
|
|
Date: Mon, 10 May 2021 18:16:20 +0200
|
2021-02-17 09:26:08 +00:00
|
|
|
Subject: [PATCH] Prevent removing of the system packages installed under
|
2020-04-26 21:10:08 +00:00
|
|
|
/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>
|
2021-05-11 14:58:03 +00:00
|
|
|
Co-Authored-By: Lumir Balhar <lbalhar@redhat.com>
|
2021-08-16 10:26:06 +00:00
|
|
|
Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
|
2019-11-12 16:31:50 +00:00
|
|
|
---
|
2021-01-26 09:11:15 +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(-)
|
|
|
|
|
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
|
2021-08-09 18:33:45 +00:00
|
|
|
index 4c58cdb..3570e17 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
|
2021-05-11 14:58:03 +00:00
|
|
|
@@ -43,6 +43,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,
|
2021-08-09 18:33:45 +00:00
|
|
|
@@ -426,7 +427,7 @@ class InstallRequirement:
|
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
|
2021-08-09 18:33:45 +00:00
|
|
|
index 4df8f7e..dda2292 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
|
2021-05-11 14:58:03 +00:00
|
|
|
@@ -42,6 +42,7 @@ from pip._internal.resolution.base import BaseResolver, InstallRequirementProvid
|
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
|
2021-08-09 18:33:45 +00:00
|
|
|
|
2021-05-11 14:58:03 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2021-08-09 18:33:45 +00:00
|
|
|
@@ -194,7 +195,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
|
2021-08-09 18:33:45 +00:00
|
|
|
|
2021-01-26 09:11:15 +00:00
|
|
|
diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py
|
2021-08-16 10:26:06 +00:00
|
|
|
index e7fd344..555e657 100644
|
2020-12-03 10:21:56 +00:00
|
|
|
--- a/src/pip/_internal/resolution/resolvelib/factory.py
|
|
|
|
+++ b/src/pip/_internal/resolution/resolvelib/factory.py
|
2021-05-11 14:58:03 +00:00
|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
import contextlib
|
2021-02-17 09:26:08 +00:00
|
|
|
import functools
|
2020-12-03 10:21:56 +00:00
|
|
|
import logging
|
|
|
|
+import sys
|
2021-05-11 14:58:03 +00:00
|
|
|
from typing import (
|
|
|
|
TYPE_CHECKING,
|
|
|
|
Dict,
|
2021-08-09 18:33:45 +00:00
|
|
|
@@ -34,6 +35,7 @@ from pip._internal.exceptions import (
|
|
|
|
UnsupportedWheel,
|
2020-12-03 10:21:56 +00:00
|
|
|
)
|
2021-08-09 18:33:45 +00:00
|
|
|
from pip._internal.index.package_finder import PackageFinder
|
2021-05-11 14:58:03 +00:00
|
|
|
+from pip._internal.locations import get_scheme
|
2021-08-09 18:33:45 +00:00
|
|
|
from pip._internal.metadata import BaseDistribution, get_default_environment
|
|
|
|
from pip._internal.models.link import Link
|
|
|
|
from pip._internal.models.wheel import Wheel
|
|
|
|
@@ -46,6 +48,7 @@ from pip._internal.req.req_install import (
|
|
|
|
from pip._internal.resolution.base import InstallRequirementProvider
|
|
|
|
from pip._internal.utils.compatibility_tags import get_supported
|
|
|
|
from pip._internal.utils.hashes import Hashes
|
|
|
|
+from pip._internal.utils.misc import dist_location
|
2020-12-03 10:21:56 +00:00
|
|
|
from pip._internal.utils.virtualenv import running_under_virtualenv
|
2021-08-09 18:33:45 +00:00
|
|
|
|
2021-05-11 14:58:03 +00:00
|
|
|
from .base import Candidate, CandidateVersion, Constraint, Requirement
|
2021-08-09 18:33:45 +00:00
|
|
|
@@ -525,6 +528,13 @@ class Factory:
|
2021-01-26 09:11:15 +00:00
|
|
|
if dist is None: # Not installed, no uninstallation required.
|
2020-12-03 10:21:56 +00:00
|
|
|
return None
|
2021-08-09 18:33:45 +00:00
|
|
|
|
2020-12-03 10:21:56 +00:00
|
|
|
+ # Prevent uninstalling packages from /usr
|
2021-08-16 10:26:06 +00:00
|
|
|
+ if dist_location(dist._dist) in (
|
2021-05-11 14:58:03 +00:00
|
|
|
+ get_scheme('', prefix=sys.base_prefix).purelib,
|
|
|
|
+ get_scheme('', prefix=sys.base_prefix).platlib,
|
2020-12-03 10:21:56 +00:00
|
|
|
+ ):
|
|
|
|
+ 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-26 09:11:15 +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
|
2021-08-09 18:33:45 +00:00
|
|
|
index 99ebea3..5901687 100644
|
2021-01-26 09:11:15 +00:00
|
|
|
--- a/src/pip/_internal/utils/misc.py
|
|
|
|
+++ b/src/pip/_internal/utils/misc.py
|
2021-05-11 14:58:03 +00:00
|
|
|
@@ -40,6 +40,7 @@ from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
|
2021-01-26 09:11:15 +00:00
|
|
|
from pip import __version__
|
|
|
|
from pip._internal.exceptions import CommandError
|
|
|
|
from pip._internal.locations import get_major_minor_version, site_packages, user_site
|
2021-05-11 14:58:03 +00:00
|
|
|
+from pip._internal.locations import get_scheme
|
2021-01-26 09:11:15 +00:00
|
|
|
from pip._internal.utils.compat import WINDOWS, stdlib_pkgs
|
|
|
|
from pip._internal.utils.virtualenv import (
|
2021-05-11 14:58:03 +00:00
|
|
|
running_under_virtualenv,
|
2021-08-09 18:33:45 +00:00
|
|
|
@@ -382,6 +383,16 @@ def dist_in_site_packages(dist):
|
2021-01-26 09:11:15 +00:00
|
|
|
return dist_location(dist).startswith(normalize_path(site_packages))
|
2021-08-09 18:33:45 +00:00
|
|
|
|
|
|
|
|
2021-01-26 09:11:15 +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(
|
2021-05-11 14:58:03 +00:00
|
|
|
+ get_scheme("").purelib.split('python')[0]))
|
2021-01-26 09:11:15 +00:00
|
|
|
+
|
|
|
|
+
|
|
|
|
def dist_is_editable(dist):
|
|
|
|
# type: (Distribution) -> bool
|
|
|
|
"""
|
2021-08-09 18:33:45 +00:00
|
|
|
--
|
|
|
|
2.32.0
|
2019-11-12 16:31:50 +00:00
|
|
|
|