4
4
import sys
5
5
from typing import List , Literal , Optional , Protocol , Type , cast
6
6
7
+ from pip ._internal .utils .deprecation import deprecated
7
8
from pip ._internal .utils .misc import strtobool
8
9
9
10
from .base import BaseDistribution , BaseEnvironment , FilesystemWheel , MemoryWheel , Wheel
@@ -54,6 +55,31 @@ def _should_use_importlib_metadata() -> bool:
54
55
return bool (getattr (importlib .metadata , "_PIP_USE_IMPORTLIB_METADATA" , True ))
55
56
56
57
58
+ def _emit_pkg_resources_deprecation_if_needed () -> None :
59
+ if sys .version_info < (3 , 11 ):
60
+ # All pip versions supporting Python<=3.11 will support pkg_resources,
61
+ # and pkg_resources is the default for these, so let's not bother users.
62
+ return
63
+
64
+ import importlib .metadata
65
+
66
+ if hasattr (importlib .metadata , "_PIP_USE_IMPORTLIB_METADATA" ):
67
+ # The Python distributor has set the global constant, so we don't
68
+ # warn, since it is not a user decision.
69
+ return
70
+
71
+ # The user has decided to use pkg_resources, so we warn.
72
+ deprecated (
73
+ reason = "Using the pkg_resources metadata backend is deprecated." ,
74
+ replacement = (
75
+ "to use the default importlib.metadata backend, "
76
+ "by unsetting the _PIP_USE_IMPORTLIB_METADATA environment variable"
77
+ ),
78
+ gone_in = "26.3" ,
79
+ issue = 13317 ,
80
+ )
81
+
82
+
57
83
class Backend (Protocol ):
58
84
NAME : 'Literal["importlib", "pkg_resources"]'
59
85
Distribution : Type [BaseDistribution ]
@@ -66,6 +92,9 @@ def select_backend() -> Backend:
66
92
from . import importlib
67
93
68
94
return cast (Backend , importlib )
95
+
96
+ _emit_pkg_resources_deprecation_if_needed ()
97
+
69
98
from . import pkg_resources
70
99
71
100
return cast (Backend , pkg_resources )
0 commit comments