Skip to content

Commit 3fda8d6

Browse files
committed
Never use the pkg_resources backend on python 3.14+
1 parent b0ebea9 commit 3fda8d6

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

news/13010.removal.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On python 3.14+, the ``pkg_resources`` metadata backend is not used anymore,
2+
and pip does not attempt to detect installed ``.egg`` distributions.

src/pip/_internal/metadata/__init__.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ def _should_use_importlib_metadata() -> bool:
3030
"""Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.
3131
3232
By default, pip uses ``importlib.metadata`` on Python 3.11+, and
33-
``pkg_resourcess`` otherwise. This can be overridden by a couple of ways:
33+
``pkg_resources`` otherwise. Up to Python 3.12, This can be
34+
overridden by a couple of ways:
3435
3536
* If environment variable ``_PIP_USE_IMPORTLIB_METADATA`` is set, it
36-
dictates whether ``importlib.metadata`` is used, regardless of Python
37-
version.
38-
* On Python 3.11+, Python distributors can patch ``importlib.metadata``
39-
to add a global constant ``_PIP_USE_IMPORTLIB_METADATA = False``. This
40-
makes pip use ``pkg_resources`` (unless the user set the aforementioned
41-
environment variable to *True*).
37+
dictates whether ``importlib.metadata`` is used, for Python <3.13.
38+
* On Python 3.11, 3.12 and 3.13, Python distributors can patch
39+
``importlib.metadata`` to add a global constant
40+
``_PIP_USE_IMPORTLIB_METADATA = False``. This makes pip use
41+
``pkg_resources`` (unless the user set the aforementioned environment
42+
variable to *True*).
4243
"""
44+
if sys.version_info >= (3, 13):
45+
return True
4346
with contextlib.suppress(KeyError, ValueError):
4447
return bool(strtobool(os.environ["_PIP_USE_IMPORTLIB_METADATA"]))
4548
if sys.version_info < (3, 11):

src/pip/_internal/metadata/importlib/_envs.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]:
173173
finder = _DistributionFinder()
174174
for location in self._paths:
175175
yield from finder.find(location)
176-
for dist in finder.find_eggs(location):
177-
_emit_egg_deprecation(dist.location)
178-
yield dist
176+
if sys.version_info < (3, 14):
177+
for dist in finder.find_eggs(location):
178+
_emit_egg_deprecation(dist.location)
179+
yield dist
179180
# This must go last because that's how pkg_resources tie-breaks.
180181
yield from finder.find_linked(location)
181182

tests/functional/test_uninstall.py

+4
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,10 @@ def test_uninstall_with_symlink(
628628
assert symlink_target.stat().st_mode == st_mode
629629

630630

631+
@pytest.mark.skipif(
632+
"sys.version_info >= (3, 14)",
633+
reason="Uninstall of .egg distributions not supported in Python 3.14+",
634+
)
631635
def test_uninstall_setuptools_develop_install(
632636
script: PipTestEnvironment, data: TestData
633637
) -> None:

0 commit comments

Comments
 (0)