Skip to content

Commit 06c8024

Browse files
authored
Merge pull request #13010 from sbidoul/always-use-importlib-metadata-on-3.13
Never use pkg_resources metadata backend on python 3.14+
2 parents 258f95e + 56d3269 commit 06c8024

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-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

+17-7
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,30 @@ def _should_use_importlib_metadata() -> bool:
2525
"""Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.
2626
2727
By default, pip uses ``importlib.metadata`` on Python 3.11+, and
28-
``pkg_resources`` otherwise. This can be overridden by a couple of ways:
28+
``pkg_resources`` otherwise. Up to Python 3.13, This can be
29+
overridden by a couple of ways:
2930
3031
* If environment variable ``_PIP_USE_IMPORTLIB_METADATA`` is set, it
31-
dictates whether ``importlib.metadata`` is used, regardless of Python
32-
version.
33-
* On Python 3.11+, Python distributors can patch ``importlib.metadata``
34-
to add a global constant ``_PIP_USE_IMPORTLIB_METADATA = False``. This
35-
makes pip use ``pkg_resources`` (unless the user set the aforementioned
36-
environment variable to *True*).
32+
dictates whether ``importlib.metadata`` is used, for Python <3.14.
33+
* On Python 3.11, 3.12 and 3.13, Python distributors can patch
34+
``importlib.metadata`` to add a global constant
35+
``_PIP_USE_IMPORTLIB_METADATA = False``. This makes pip use
36+
``pkg_resources`` (unless the user set the aforementioned environment
37+
variable to *True*).
38+
39+
On Python 3.14+, the ``pkg_resources`` backend cannot be used.
3740
"""
41+
if sys.version_info >= (3, 14):
42+
# On Python >=3.14 we only support importlib.metadata.
43+
return True
3844
with contextlib.suppress(KeyError, ValueError):
45+
# On Python <3.14, if the environment variable is set, we obey what it says.
3946
return bool(strtobool(os.environ["_PIP_USE_IMPORTLIB_METADATA"]))
4047
if sys.version_info < (3, 11):
48+
# On Python <3.11, we always use pkg_resources, unless the environment
49+
# variable was set.
4150
return False
51+
# On Python 3.11, 3.12 and 3.13, we check if the global constant is set.
4252
import importlib.metadata
4353

4454
return bool(getattr(importlib.metadata, "_PIP_USE_IMPORTLIB_METADATA", True))

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]:
179179
finder = _DistributionFinder()
180180
for location in self._paths:
181181
yield from finder.find(location)
182-
for dist in finder.find_eggs(location):
183-
_emit_egg_deprecation(dist.location)
184-
yield dist
182+
if sys.version_info < (3, 14):
183+
for dist in finder.find_eggs(location):
184+
_emit_egg_deprecation(dist.location)
185+
yield dist
185186
# This must go last because that's how pkg_resources tie-breaks.
186187
yield from finder.find_linked(location)
187188

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)