2022-06-29 00:26:42 +00:00
|
|
|
From 2c3f3a590ddfc151a456b44a5f96f0f603d178e9 Mon Sep 17 00:00:00 2001
|
2022-02-16 07:58:06 +00:00
|
|
|
From: Lumir Balhar <lbalhar@redhat.com>
|
|
|
|
Date: Wed, 16 Feb 2022 08:36:21 +0100
|
2021-02-17 09:26:08 +00:00
|
|
|
Subject: [PATCH] Prevent removing of the system packages installed under
|
2022-02-16 07:58:06 +00:00
|
|
|
/usr/lib when pip install --upgrade is executed.
|
2021-09-23 12:56:56 +00:00
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
2018-08-30 13:27:55 +00:00
|
|
|
|
2019-11-12 16:31:50 +00:00
|
|
|
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>
|
2022-02-16 07:58:06 +00:00
|
|
|
Co-Authored-By: Karolina Surma <ksurma@redhat.com>
|
2019-11-12 16:31:50 +00:00
|
|
|
---
|
2022-02-16 07:58:06 +00:00
|
|
|
src/pip/_internal/metadata/base.py | 12 +++++++++++-
|
|
|
|
src/pip/_internal/req/req_install.py | 2 +-
|
|
|
|
src/pip/_internal/resolution/legacy/resolver.py | 4 +++-
|
|
|
|
src/pip/_internal/resolution/resolvelib/factory.py | 12 ++++++++++++
|
|
|
|
4 files changed, 27 insertions(+), 3 deletions(-)
|
2021-01-26 09:11:15 +00:00
|
|
|
|
2022-02-16 07:58:06 +00:00
|
|
|
diff --git a/src/pip/_internal/metadata/base.py b/src/pip/_internal/metadata/base.py
|
2022-06-29 00:26:42 +00:00
|
|
|
index 151fd6d..f9109cd 100644
|
2022-02-16 07:58:06 +00:00
|
|
|
--- a/src/pip/_internal/metadata/base.py
|
|
|
|
+++ b/src/pip/_internal/metadata/base.py
|
2022-06-29 00:26:42 +00:00
|
|
|
@@ -28,7 +28,7 @@ from pip._vendor.packaging.utils import NormalizedName
|
2022-02-16 07:58:06 +00:00
|
|
|
from pip._vendor.packaging.version import LegacyVersion, Version
|
|
|
|
|
|
|
|
from pip._internal.exceptions import NoneMetadataError
|
|
|
|
-from pip._internal.locations import site_packages, user_site
|
|
|
|
+from pip._internal.locations import get_scheme, site_packages, user_site
|
|
|
|
from pip._internal.models.direct_url import (
|
|
|
|
DIRECT_URL_METADATA_NAME,
|
|
|
|
DirectUrl,
|
2022-06-29 00:26:42 +00:00
|
|
|
@@ -560,6 +560,16 @@ class BaseDistribution(Protocol):
|
|
|
|
for extra in self._iter_egg_info_extras():
|
|
|
|
metadata["Provides-Extra"] = extra
|
2022-02-16 07:58:06 +00:00
|
|
|
|
|
|
|
+ @property
|
|
|
|
+ def in_install_path(self) -> bool:
|
|
|
|
+ """
|
|
|
|
+ Return True if given Distribution is installed in
|
|
|
|
+ path matching distutils_scheme layout.
|
|
|
|
+ """
|
|
|
|
+ norm_path = normalize_path(self.installed_location)
|
|
|
|
+ return norm_path.startswith(normalize_path(
|
|
|
|
+ get_scheme("").purelib.split('python')[0]))
|
|
|
|
+
|
|
|
|
|
|
|
|
class BaseEnvironment:
|
|
|
|
"""An environment containing distributions to introspect."""
|
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
|
2022-06-29 00:26:42 +00:00
|
|
|
index a1e376c..ed7facf 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
|
2022-06-29 00:26:42 +00:00
|
|
|
@@ -416,7 +416,7 @@ class InstallRequirement:
|
2022-02-16 07:58:06 +00:00
|
|
|
f"lack sys.path precedence to {existing_dist.raw_name} "
|
|
|
|
f"in {existing_dist.location}"
|
2018-08-30 13:27:55 +00:00
|
|
|
)
|
|
|
|
- else:
|
2022-02-16 07:58:06 +00:00
|
|
|
+ elif existing_dist.in_install_path:
|
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
|
2022-06-29 00:26:42 +00:00
|
|
|
index fb49d41..040f2c1 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
|
2022-06-29 00:26:42 +00:00
|
|
|
@@ -325,7 +325,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.
|
2022-02-16 07:58:06 +00:00
|
|
|
- if not self.use_user_site or req.satisfied_by.in_usersite:
|
2020-04-26 21:10:08 +00:00
|
|
|
+ if ((not self.use_user_site
|
2022-02-16 07:58:06 +00:00
|
|
|
+ or req.satisfied_by.in_usersite)
|
|
|
|
+ and req.satisfied_by.in_install_path):
|
2020-04-26 21:10:08 +00:00
|
|
|
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
|
2022-06-29 00:26:42 +00:00
|
|
|
index a4c24b5..e7e2da9 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-10-15 07:36:43 +00:00
|
|
|
@@ -1,6 +1,8 @@
|
2021-05-11 14:58:03 +00:00
|
|
|
import contextlib
|
2021-02-17 09:26:08 +00:00
|
|
|
import functools
|
2020-12-03 10:21:56 +00:00
|
|
|
import logging
|
2021-10-15 07:36:43 +00:00
|
|
|
+import sys
|
2021-09-23 12:56:56 +00:00
|
|
|
+import sysconfig
|
2021-05-11 14:58:03 +00:00
|
|
|
from typing import (
|
|
|
|
TYPE_CHECKING,
|
|
|
|
Dict,
|
2022-06-29 00:26:42 +00:00
|
|
|
@@ -549,6 +551,16 @@ 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-09-23 12:56:56 +00:00
|
|
|
+ try:
|
2022-02-16 07:58:06 +00:00
|
|
|
+ if dist.installed_location in (
|
2021-10-15 07:36:43 +00:00
|
|
|
+ sysconfig.get_path('purelib', scheme='rpm_prefix', vars={'base': sys.base_prefix}),
|
|
|
|
+ sysconfig.get_path('platlib', scheme='rpm_prefix', vars={'base': sys.base_prefix}),
|
2022-02-16 07:58:06 +00:00
|
|
|
+ ):
|
2021-09-23 12:56:56 +00:00
|
|
|
+ return None
|
|
|
|
+ except KeyError: # this Python doesn't have 'rpm_prefix' scheme yet
|
|
|
|
+ pass
|
2020-12-03 10:21:56 +00:00
|
|
|
+
|
|
|
|
# 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.
|
2021-08-09 18:33:45 +00:00
|
|
|
--
|
2022-06-29 00:26:42 +00:00
|
|
|
2.35.3
|
2019-11-12 16:31:50 +00:00
|
|
|
|