@@ -25,20 +25,30 @@ def _should_use_importlib_metadata() -> bool:
25
25
"""Whether to use the ``importlib.metadata`` or ``pkg_resources`` backend.
26
26
27
27
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:
29
30
30
31
* 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.
37
40
"""
41
+ if sys .version_info >= (3 , 14 ):
42
+ # On Python >=3.14 we only support importlib.metadata.
43
+ return True
38
44
with contextlib .suppress (KeyError , ValueError ):
45
+ # On Python <3.14, if the environment variable is set, we obey what it says.
39
46
return bool (strtobool (os .environ ["_PIP_USE_IMPORTLIB_METADATA" ]))
40
47
if sys .version_info < (3 , 11 ):
48
+ # On Python <3.11, we always use pkg_resources, unless the environment
49
+ # variable was set.
41
50
return False
51
+ # On Python 3.11, 3.12 and 3.13, we check if the global constant is set.
42
52
import importlib .metadata
43
53
44
54
return bool (getattr (importlib .metadata , "_PIP_USE_IMPORTLIB_METADATA" , True ))
0 commit comments