14
14
15
15
"""Utility class to inspect an extracted wheel directory"""
16
16
17
- from __future__ import annotations
18
-
19
17
import email
20
18
from collections import defaultdict
21
19
from dataclasses import dataclass , field
22
20
from enum import Enum , unique
21
+ from pathlib import Path
22
+ from typing import Dict , List , Optional , Set , Tuple
23
23
24
24
import installer
25
25
import pkg_resources
@@ -33,7 +33,7 @@ class OS(Enum):
33
33
windows = 3
34
34
35
35
@staticmethod
36
- def from_tag (tag : str ) -> OS :
36
+ def from_tag (tag : str ) -> "OS" :
37
37
if tag .startswith ("linux" ):
38
38
return OS .linux
39
39
elif tag .startswith ("manylinux" ):
@@ -89,7 +89,7 @@ def __str__(self) -> str:
89
89
return self .os .name .lower () + "_" + self .arch .name .lower ()
90
90
91
91
@classmethod
92
- def from_tag (cls , tag : str ) -> Platform :
92
+ def from_tag (cls , tag : str ) -> " Platform" :
93
93
return cls (
94
94
os = OS .from_tag (tag ),
95
95
arch = Arch .from_tag (tag ),
@@ -161,18 +161,18 @@ def _default_select():
161
161
162
162
@dataclass
163
163
class Deps :
164
- deps : set [str ] = field (default_factory = set )
165
- select : dict [Platform , set [str ]] = field (default_factory = _default_select )
164
+ deps : Set [str ] = field (default_factory = set )
165
+ select : Dict [Platform , Set [str ]] = field (default_factory = _default_select )
166
166
167
- def add (self , dep : str , platform : Platform | None = None ):
167
+ def add (self , dep : str , platform : Optional [ Platform ] = None ):
168
168
if platform :
169
169
self .select [platform ].add (dep )
170
170
else :
171
171
self .deps .add (dep )
172
172
for p , deps in self .select .items ():
173
173
self .select [p ] = deps - {dep }
174
174
175
- def build (self , all_platforms : list [Platform ]) -> Deps :
175
+ def build (self , all_platforms : List [Platform ]) -> " Deps" :
176
176
# Move deps to common deps if they are present for all platforms
177
177
common_deps = None
178
178
for plat in all_platforms :
@@ -192,7 +192,7 @@ def build(self, all_platforms: list[Platform]) -> Deps:
192
192
class Wheel :
193
193
"""Representation of the compressed .whl file"""
194
194
195
- def __init__ (self , path : str ):
195
+ def __init__ (self , path : Path ):
196
196
self ._path = path
197
197
198
198
@property
@@ -217,13 +217,13 @@ def version(self) -> str:
217
217
# TODO Also available as installer.sources.WheelSource.version
218
218
return str (self .metadata ["Version" ])
219
219
220
- def entry_points (self ) -> dict [str , tuple [str , str ]]:
220
+ def entry_points (self ) -> Dict [str , Tuple [str , str ]]:
221
221
"""Returns the entrypoints defined in the current wheel
222
222
223
223
See https://packaging.python.org/specifications/entry-points/ for more info
224
224
225
225
Returns:
226
- dict [str, tuple [str, str]]: A mapping of the entry point's name to it's module and attribute
226
+ Dict [str, Tuple [str, str]]: A mapping of the entry point's name to it's module and attribute
227
227
"""
228
228
with installer .sources .WheelFile .open (self .path ) as wheel_source :
229
229
if "entry_points.txt" not in wheel_source .dist_info_filenames :
@@ -239,7 +239,7 @@ def entry_points(self) -> dict[str, tuple[str, str]]:
239
239
return entry_points_mapping
240
240
241
241
def dependencies (
242
- self , extras_requested : set [str ] = None , platforms = list [Platform ]
242
+ self , extras_requested : Set [str ] = None , platforms = List [Platform ]
243
243
) -> Deps :
244
244
# NOTE @aignas 2023-12-04: if the wheel is a platform specific wheel, we only include deps for that platform
245
245
_ , _ , platform_tag = self ._path .name .rpartition ("-" )
0 commit comments