2727if sys .version_info < (3 , 8 ): # noqa: UP036 # Check for unsupported versions
2828 raise RuntimeError ("Python 3.8 or later is required" )
2929
30- import os
30+ import _imp
31+ import collections
32+ import email .parser
33+ import errno
34+ import functools
35+ import importlib
36+ import importlib .abc
37+ import importlib .machinery
38+ import inspect
3139import io
32- import time
40+ import ntpath
41+ import operator
42+ import os
43+ import pkgutil
44+ import platform
45+ import plistlib
46+ import posixpath
3347import re
48+ import stat
49+ import tempfile
50+ import textwrap
51+ import time
3452import types
53+ import warnings
54+ import zipfile
55+ import zipimport
56+ from pkgutil import get_importer
3557from typing import (
58+ TYPE_CHECKING ,
3659 Any ,
3760 BinaryIO ,
38- Literal ,
61+ Callable ,
3962 Dict ,
63+ Iterable ,
4064 Iterator ,
65+ Literal ,
4166 Mapping ,
4267 MutableSequence ,
4368 NamedTuple ,
4469 NoReturn ,
45- Tuple ,
46- Union ,
47- TYPE_CHECKING ,
4870 Protocol ,
49- Callable ,
50- Iterable ,
71+ Tuple ,
5172 TypeVar ,
73+ Union ,
5274 overload ,
5375)
54- import zipfile
55- import zipimport
56- import warnings
57- import stat
58- import functools
59- import pkgutil
60- import operator
61- import platform
62- import collections
63- import plistlib
64- import email .parser
65- import errno
66- import tempfile
67- import textwrap
68- import inspect
69- import ntpath
70- import posixpath
71- import importlib
72- import importlib .abc
73- import importlib .machinery
74- from pkgutil import get_importer
75-
76- import _imp
7776
7877sys .path .extend (((vendor_path := os .path .join (os .path .dirname (os .path .dirname (__file__ )), 'setuptools' , '_vendor' )) not in sys .path ) * [vendor_path ]) # fmt: skip
7978# workaround for #4476
8079sys .modules .pop ('backports' , None )
8180
8281# capture these to bypass sandboxing
83- from os import utime
84- from os import open as os_open
85- from os .path import isdir , split
82+ from os import open as os_open , utime # isort: skip
83+ from os .path import isdir , split # isort: skip
8684
8785try :
8886 from os import mkdir , rename , unlink
9290 # no write support, probably under GAE
9391 WRITE_SUPPORT = False
9492
93+ import packaging .markers
94+ import packaging .requirements
9595import packaging .specifiers
96- from jaraco .text import (
97- yield_lines ,
98- drop_comment ,
99- join_continuation ,
100- )
101- from packaging import markers as _packaging_markers
102- from packaging import requirements as _packaging_requirements
103- from packaging import utils as _packaging_utils
104- from packaging import version as _packaging_version
96+ import packaging .utils
97+ import packaging .version
98+ from jaraco .text import drop_comment , join_continuation , yield_lines
10599from platformdirs import user_cache_dir as _user_cache_dir
106100
107101if TYPE_CHECKING :
108- from _typeshed import BytesPath , StrPath , StrOrBytesPath
109- from typing_extensions import Self
102+ from _typeshed import BytesPath , StrOrBytesPath , StrPath
103+ from typing_extensions import Self , TypeAlias
110104
111105warnings .warn (
112106 "pkg_resources is deprecated as an API. "
118112_T = TypeVar ("_T" )
119113_DistributionT = TypeVar ("_DistributionT" , bound = "Distribution" )
120114# Type aliases
121- _NestedStr = Union [str , Iterable [Union [str , Iterable ["_NestedStr" ]]]]
122- _InstallerTypeT = Callable [["Requirement" ], "_DistributionT" ]
123- _InstallerType = Callable [["Requirement" ], Union ["Distribution" , None ]]
124- _PkgReqType = Union [str , "Requirement" ]
125- _EPDistType = Union ["Distribution" , _PkgReqType ]
126- _MetadataType = Union ["IResourceProvider" , None ]
127- _ResolvedEntryPoint = Any # Can be any attribute in the module
128- _ResourceStream = Any # TODO / Incomplete: A readable file-like object
115+ _NestedStr : TypeAlias = Union [str , Iterable [Union [str , Iterable ["_NestedStr" ]]]]
116+ _StrictInstallerType : TypeAlias = Callable [["Requirement" ], "_DistributionT" ]
117+ _InstallerType : TypeAlias = Callable [["Requirement" ], Union ["Distribution" , None ]]
118+ _PkgReqType : TypeAlias = Union [str , "Requirement" ]
119+ _EPDistType : TypeAlias = Union ["Distribution" , _PkgReqType ]
120+ _MetadataType : TypeAlias = Union ["IResourceProvider" , None ]
121+ _ResolvedEntryPoint : TypeAlias = Any # Can be any attribute in the module
122+ _ResourceStream : TypeAlias = Any # TODO / Incomplete: A readable file-like object
129123# Any object works, but let's indicate we expect something like a module (optionally has __loader__ or __file__)
130- _ModuleLike = Union [object , types .ModuleType ]
124+ _ModuleLike : TypeAlias = Union [object , types .ModuleType ]
131125# Any: Should be _ModuleLike but we end up with issues where _ModuleLike doesn't have _ZipLoaderModule's __loader__
132- _ProviderFactoryType = Callable [[Any ], "IResourceProvider" ]
133- _DistFinderType = Callable [[_T , str , bool ], Iterable ["Distribution" ]]
134- _NSHandlerType = Callable [[_T , str , str , types .ModuleType ], Union [str , None ]]
126+ _ProviderFactoryType : TypeAlias = Callable [[Any ], "IResourceProvider" ]
127+ _DistFinderType : TypeAlias = Callable [[_T , str , bool ], Iterable ["Distribution" ]]
128+ _NSHandlerType : TypeAlias = Callable [[_T , str , str , types .ModuleType ], Union [str , None ]]
135129_AdapterT = TypeVar (
136130 "_AdapterT" , _DistFinderType [Any ], _ProviderFactoryType , _NSHandlerType [Any ]
137131)
@@ -156,7 +150,7 @@ class PEP440Warning(RuntimeWarning):
156150 """
157151
158152
159- parse_version = _packaging_version .Version
153+ parse_version = packaging . version .Version
160154
161155_state_vars : dict [str , str ] = {}
162156
@@ -801,7 +795,7 @@ def add(
801795 return
802796
803797 self .by_key [dist .key ] = dist
804- normalized_name = _packaging_utils .canonicalize_name (dist .key )
798+ normalized_name = packaging . utils .canonicalize_name (dist .key )
805799 self .normalized_to_canonical_keys [normalized_name ] = dist .key
806800 if dist .key not in keys :
807801 keys .append (dist .key )
@@ -814,7 +808,7 @@ def resolve(
814808 self ,
815809 requirements : Iterable [Requirement ],
816810 env : Environment | None ,
817- installer : _InstallerTypeT [_DistributionT ],
811+ installer : _StrictInstallerType [_DistributionT ],
818812 replace_conflicting : bool = False ,
819813 extras : tuple [str , ...] | None = None ,
820814 ) -> list [_DistributionT ]: ...
@@ -824,7 +818,7 @@ def resolve(
824818 requirements : Iterable [Requirement ],
825819 env : Environment | None = None ,
826820 * ,
827- installer : _InstallerTypeT [_DistributionT ],
821+ installer : _StrictInstallerType [_DistributionT ],
828822 replace_conflicting : bool = False ,
829823 extras : tuple [str , ...] | None = None ,
830824 ) -> list [_DistributionT ]: ...
@@ -841,7 +835,7 @@ def resolve(
841835 self ,
842836 requirements : Iterable [Requirement ],
843837 env : Environment | None = None ,
844- installer : _InstallerType | None | _InstallerTypeT [_DistributionT ] = None ,
838+ installer : _InstallerType | None | _StrictInstallerType [_DistributionT ] = None ,
845839 replace_conflicting : bool = False ,
846840 extras : tuple [str , ...] | None = None ,
847841 ) -> list [Distribution ] | list [_DistributionT ]:
@@ -947,7 +941,7 @@ def find_plugins(
947941 self ,
948942 plugin_env : Environment ,
949943 full_env : Environment | None ,
950- installer : _InstallerTypeT [_DistributionT ],
944+ installer : _StrictInstallerType [_DistributionT ],
951945 fallback : bool = True ,
952946 ) -> tuple [list [_DistributionT ], dict [Distribution , Exception ]]: ...
953947 @overload
@@ -956,7 +950,7 @@ def find_plugins(
956950 plugin_env : Environment ,
957951 full_env : Environment | None = None ,
958952 * ,
959- installer : _InstallerTypeT [_DistributionT ],
953+ installer : _StrictInstallerType [_DistributionT ],
960954 fallback : bool = True ,
961955 ) -> tuple [list [_DistributionT ], dict [Distribution , Exception ]]: ...
962956 @overload
@@ -971,7 +965,7 @@ def find_plugins(
971965 self ,
972966 plugin_env : Environment ,
973967 full_env : Environment | None = None ,
974- installer : _InstallerType | None | _InstallerTypeT [_DistributionT ] = None ,
968+ installer : _InstallerType | None | _StrictInstallerType [_DistributionT ] = None ,
975969 fallback : bool = True ,
976970 ) -> tuple [
977971 list [Distribution ] | list [_DistributionT ],
@@ -1217,7 +1211,7 @@ def best_match(
12171211 self ,
12181212 req : Requirement ,
12191213 working_set : WorkingSet ,
1220- installer : _InstallerTypeT [_DistributionT ],
1214+ installer : _StrictInstallerType [_DistributionT ],
12211215 replace_conflicting : bool = False ,
12221216 ) -> _DistributionT : ...
12231217 @overload
@@ -1232,7 +1226,7 @@ def best_match(
12321226 self ,
12331227 req : Requirement ,
12341228 working_set : WorkingSet ,
1235- installer : _InstallerType | None | _InstallerTypeT [_DistributionT ] = None ,
1229+ installer : _InstallerType | None | _StrictInstallerType [_DistributionT ] = None ,
12361230 replace_conflicting : bool = False ,
12371231 ) -> Distribution | None :
12381232 """Find distribution best matching `req` and usable on `working_set`
@@ -1265,7 +1259,7 @@ def best_match(
12651259 def obtain (
12661260 self ,
12671261 requirement : Requirement ,
1268- installer : _InstallerTypeT [_DistributionT ],
1262+ installer : _StrictInstallerType [_DistributionT ],
12691263 ) -> _DistributionT : ...
12701264 @overload
12711265 def obtain (
@@ -1285,7 +1279,7 @@ def obtain(
12851279 installer : Callable [[Requirement ], None ]
12861280 | _InstallerType
12871281 | None
1288- | _InstallerTypeT [_DistributionT ] = None ,
1282+ | _StrictInstallerType [_DistributionT ] = None ,
12891283 ) -> Distribution | None :
12901284 """Obtain a distribution matching `requirement` (e.g. via download)
12911285
@@ -1561,8 +1555,8 @@ def safe_version(version: str) -> str:
15611555 """
15621556 try :
15631557 # normalize the version
1564- return str (_packaging_version .Version (version ))
1565- except _packaging_version .InvalidVersion :
1558+ return str (packaging . version .Version (version ))
1559+ except packaging . version .InvalidVersion :
15661560 version = version .replace (' ' , '.' )
15671561 return re .sub ('[^A-Za-z0-9.]+' , '-' , version )
15681562
@@ -1639,9 +1633,9 @@ def evaluate_marker(text: str, extra: str | None = None) -> bool:
16391633 This implementation uses the 'pyparsing' module.
16401634 """
16411635 try :
1642- marker = _packaging_markers .Marker (text )
1636+ marker = packaging . markers .Marker (text )
16431637 return marker .evaluate ()
1644- except _packaging_markers .InvalidMarker as e :
1638+ except packaging . markers .InvalidMarker as e :
16451639 raise SyntaxError (e ) from e
16461640
16471641
@@ -3001,20 +2995,20 @@ def parsed_version(self):
30012995 if not hasattr (self , "_parsed_version" ):
30022996 try :
30032997 self ._parsed_version = parse_version (self .version )
3004- except _packaging_version .InvalidVersion as ex :
2998+ except packaging . version .InvalidVersion as ex :
30052999 info = f"(package: { self .project_name } )"
30063000 if hasattr (ex , "add_note" ):
30073001 ex .add_note (info ) # PEP 678
30083002 raise
3009- raise _packaging_version .InvalidVersion (f"{ str (ex )} { info } " ) from None
3003+ raise packaging . version .InvalidVersion (f"{ str (ex )} { info } " ) from None
30103004
30113005 return self ._parsed_version
30123006
30133007 @property
30143008 def _forgiving_parsed_version (self ):
30153009 try :
30163010 return self .parsed_version
3017- except _packaging_version .InvalidVersion as ex :
3011+ except packaging . version .InvalidVersion as ex :
30183012 self ._parsed_version = parse_version (_forgiving_version (self .version ))
30193013
30203014 notes = "\n " .join (getattr (ex , "__notes__" , [])) # PEP 678
@@ -3194,7 +3188,7 @@ def from_filename(
31943188
31953189 def as_requirement (self ):
31963190 """Return a ``Requirement`` that matches this distribution exactly"""
3197- if isinstance (self .parsed_version , _packaging_version .Version ):
3191+ if isinstance (self .parsed_version , packaging . version .Version ):
31983192 spec = "%s==%s" % (self .project_name , self .parsed_version )
31993193 else :
32003194 spec = "%s===%s" % (self .project_name , self .parsed_version )
@@ -3452,11 +3446,11 @@ def parse_requirements(strs: _NestedStr) -> map[Requirement]:
34523446 return map (Requirement , join_continuation (map (drop_comment , yield_lines (strs ))))
34533447
34543448
3455- class RequirementParseError (_packaging_requirements .InvalidRequirement ):
3449+ class RequirementParseError (packaging . requirements .InvalidRequirement ):
34563450 "Compatibility wrapper for InvalidRequirement"
34573451
34583452
3459- class Requirement (_packaging_requirements .Requirement ):
3453+ class Requirement (packaging . requirements .Requirement ):
34603454 # prefer variable length tuple to set (as found in
34613455 # packaging.requirements.Requirement)
34623456 extras : tuple [str , ...] # type: ignore[assignment]
0 commit comments