Skip to content

Commit 0ee7f85

Browse files
committed
Silently ignore pkg_resources override on 3.12+
This customization is generally provided by the distributor, and the user can do nothing if the environment is configured incorrectly. So instead of breaking pip entirely, we silently ignore the customization and let the distributor correct the situation.
1 parent 5b1afe5 commit 0ee7f85

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/pip/_internal/metadata/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55
from typing import TYPE_CHECKING, List, Optional, Type, cast
66

7-
from pip._internal.exceptions import PipError
87
from pip._internal.utils.misc import strtobool
98

109
from .base import BaseDistribution, BaseEnvironment, FilesystemWheel, MemoryWheel, Wheel
@@ -31,7 +30,8 @@ def _should_use_importlib_metadata() -> bool:
3130
"""Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.
3231
3332
By default, pip uses ``importlib.metadata`` on Python 3.11+, and
34-
``pkg_resourcess`` otherwise. This can be overridden by a couple of ways:
33+
``pkg_resources`` otherwise. On Python versions prior to 3.12, this can be
34+
overridden by a couple of ways for transitional purposes:
3535
3636
* If environment variable ``_PIP_USE_IMPORTLIB_METADATA`` is set, it
3737
dictates whether ``importlib.metadata`` is used, regardless of Python
@@ -41,6 +41,8 @@ def _should_use_importlib_metadata() -> bool:
4141
makes pip use ``pkg_resources`` (unless the user set the aforementioned
4242
environment variable to *True*).
4343
"""
44+
if sys.version_info >= (3, 12):
45+
return True
4446
with contextlib.suppress(KeyError, ValueError):
4547
return bool(strtobool(os.environ["_PIP_USE_IMPORTLIB_METADATA"]))
4648
if sys.version_info < (3, 11):
@@ -61,11 +63,6 @@ def select_backend() -> Backend:
6163
from . import importlib
6264

6365
return cast(Backend, importlib)
64-
65-
if sys.version_info >= (3, 12):
66-
message = "Cannot use pkg_resources as metadata backend on Python 3.12+"
67-
raise PipError(message)
68-
6966
from . import pkg_resources
7067

7168
return cast(Backend, pkg_resources)

0 commit comments

Comments
 (0)