20
20
logger = logging .getLogger (__name__ )
21
21
22
22
23
- def _hash_dict (d ):
24
- # type: (Dict[str, str]) -> str
23
+ def _hash_dict (d : Dict [str , str ]) -> str :
25
24
"""Return a stable sha224 of a dictionary."""
26
25
s = json .dumps (d , sort_keys = True , separators = ("," , ":" ), ensure_ascii = True )
27
26
return hashlib .sha224 (s .encode ("ascii" )).hexdigest ()
@@ -38,8 +37,9 @@ class Cache:
38
37
('binary' and 'source' are the only allowed values)
39
38
"""
40
39
41
- def __init__ (self , cache_dir , format_control , allowed_formats ):
42
- # type: (str, FormatControl, Set[str]) -> None
40
+ def __init__ (
41
+ self , cache_dir : str , format_control : FormatControl , allowed_formats : Set [str ]
42
+ ) -> None :
43
43
super ().__init__ ()
44
44
assert not cache_dir or os .path .isabs (cache_dir )
45
45
self .cache_dir = cache_dir or None
@@ -49,8 +49,7 @@ def __init__(self, cache_dir, format_control, allowed_formats):
49
49
_valid_formats = {"source" , "binary" }
50
50
assert self .allowed_formats .union (_valid_formats ) == _valid_formats
51
51
52
- def _get_cache_path_parts (self , link ):
53
- # type: (Link) -> List[str]
52
+ def _get_cache_path_parts (self , link : Link ) -> List [str ]:
54
53
"""Get parts of part that must be os.path.joined with cache_dir
55
54
"""
56
55
@@ -84,8 +83,7 @@ def _get_cache_path_parts(self, link):
84
83
85
84
return parts
86
85
87
- def _get_candidates (self , link , canonical_package_name ):
88
- # type: (Link, str) -> List[Any]
86
+ def _get_candidates (self , link : Link , canonical_package_name : str ) -> List [Any ]:
89
87
can_not_cache = (
90
88
not self .cache_dir or
91
89
not canonical_package_name or
@@ -107,19 +105,17 @@ def _get_candidates(self, link, canonical_package_name):
107
105
candidates .append ((candidate , path ))
108
106
return candidates
109
107
110
- def get_path_for_link (self , link ):
111
- # type: (Link) -> str
108
+ def get_path_for_link (self , link : Link ) -> str :
112
109
"""Return a directory to store cached items in for link.
113
110
"""
114
111
raise NotImplementedError ()
115
112
116
113
def get (
117
114
self ,
118
- link , # type: Link
119
- package_name , # type: Optional[str]
120
- supported_tags , # type: List[Tag]
121
- ):
122
- # type: (...) -> Link
115
+ link : Link ,
116
+ package_name : Optional [str ],
117
+ supported_tags : List [Tag ],
118
+ ) -> Link :
123
119
"""Returns a link to a cached item if it exists, otherwise returns the
124
120
passed link.
125
121
"""
@@ -130,12 +126,10 @@ class SimpleWheelCache(Cache):
130
126
"""A cache of wheels for future installs.
131
127
"""
132
128
133
- def __init__ (self , cache_dir , format_control ):
134
- # type: (str, FormatControl) -> None
129
+ def __init__ (self , cache_dir : str , format_control : FormatControl ) -> None :
135
130
super ().__init__ (cache_dir , format_control , {"binary" })
136
131
137
- def get_path_for_link (self , link ):
138
- # type: (Link) -> str
132
+ def get_path_for_link (self , link : Link ) -> str :
139
133
"""Return a directory to store cached wheels for link
140
134
141
135
Because there are M wheels for any one sdist, we provide a directory
@@ -157,11 +151,10 @@ def get_path_for_link(self, link):
157
151
158
152
def get (
159
153
self ,
160
- link , # type: Link
161
- package_name , # type: Optional[str]
162
- supported_tags , # type: List[Tag]
163
- ):
164
- # type: (...) -> Link
154
+ link : Link ,
155
+ package_name : Optional [str ],
156
+ supported_tags : List [Tag ],
157
+ ) -> Link :
165
158
candidates = []
166
159
167
160
if not package_name :
@@ -204,8 +197,7 @@ class EphemWheelCache(SimpleWheelCache):
204
197
"""A SimpleWheelCache that creates it's own temporary cache directory
205
198
"""
206
199
207
- def __init__ (self , format_control ):
208
- # type: (FormatControl) -> None
200
+ def __init__ (self , format_control : FormatControl ) -> None :
209
201
self ._temp_dir = TempDirectory (
210
202
kind = tempdir_kinds .EPHEM_WHEEL_CACHE ,
211
203
globally_managed = True ,
@@ -217,8 +209,8 @@ def __init__(self, format_control):
217
209
class CacheEntry :
218
210
def __init__ (
219
211
self ,
220
- link , # type : Link
221
- persistent , # type : bool
212
+ link : Link ,
213
+ persistent : bool ,
222
214
):
223
215
self .link = link
224
216
self .persistent = persistent
@@ -231,39 +223,34 @@ class WheelCache(Cache):
231
223
when a certain link is not found in the simple wheel cache first.
232
224
"""
233
225
234
- def __init__ (self , cache_dir , format_control ):
235
- # type: (str, FormatControl) -> None
226
+ def __init__ (self , cache_dir : str , format_control : FormatControl ) -> None :
236
227
super ().__init__ (cache_dir , format_control , {'binary' })
237
228
self ._wheel_cache = SimpleWheelCache (cache_dir , format_control )
238
229
self ._ephem_cache = EphemWheelCache (format_control )
239
230
240
- def get_path_for_link (self , link ):
241
- # type: (Link) -> str
231
+ def get_path_for_link (self , link : Link ) -> str :
242
232
return self ._wheel_cache .get_path_for_link (link )
243
233
244
- def get_ephem_path_for_link (self , link ):
245
- # type: (Link) -> str
234
+ def get_ephem_path_for_link (self , link : Link ) -> str :
246
235
return self ._ephem_cache .get_path_for_link (link )
247
236
248
237
def get (
249
238
self ,
250
- link , # type: Link
251
- package_name , # type: Optional[str]
252
- supported_tags , # type: List[Tag]
253
- ):
254
- # type: (...) -> Link
239
+ link : Link ,
240
+ package_name : Optional [str ],
241
+ supported_tags : List [Tag ],
242
+ ) -> Link :
255
243
cache_entry = self .get_cache_entry (link , package_name , supported_tags )
256
244
if cache_entry is None :
257
245
return link
258
246
return cache_entry .link
259
247
260
248
def get_cache_entry (
261
249
self ,
262
- link , # type: Link
263
- package_name , # type: Optional[str]
264
- supported_tags , # type: List[Tag]
265
- ):
266
- # type: (...) -> Optional[CacheEntry]
250
+ link : Link ,
251
+ package_name : Optional [str ],
252
+ supported_tags : List [Tag ],
253
+ ) -> Optional [CacheEntry ]:
267
254
"""Returns a CacheEntry with a link to a cached item if it exists or
268
255
None. The cache entry indicates if the item was found in the persistent
269
256
or ephemeral cache.
0 commit comments