Skip to content

Commit 84c50f5

Browse files
committed
Never use the pkg_resources backend on python 3.13+
1 parent b0ebea9 commit 84c50f5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/pip/_internal/metadata/__init__.py

+7-4
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_resourcess`` On Python <3.13. 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
3637
dictates whether ``importlib.metadata`` is used, regardless of Python
3738
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
39+
* On Python 3.11+, Python distributors can patch ``importlib.metadata`` to
40+
add a global constant ``_PIP_USE_IMPORTLIB_METADATA = False``. This makes
41+
pip use ``pkg_resources`` (unless the user set the aforementioned
4142
environment 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, 13):
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, 13)",
633+
reason="Uninstall of .egg distributions not supported in Python 3.13+",
634+
)
631635
def test_uninstall_setuptools_develop_install(
632636
script: PipTestEnvironment, data: TestData
633637
) -> None:

0 commit comments

Comments
 (0)