39
39
operators = Specifier ._operators .keys ()
40
40
41
41
42
- def _strip_extras (path ):
43
- # type: (str) -> Tuple[str, Optional[str]]
42
+ def _strip_extras (path : str ) -> Tuple [str , Optional [str ]]:
44
43
m = re .match (r'^(.+)(\[[^\]]+\])$' , path )
45
44
extras = None
46
45
if m :
@@ -52,15 +51,13 @@ def _strip_extras(path):
52
51
return path_no_extras , extras
53
52
54
53
55
- def convert_extras (extras ):
56
- # type: (Optional[str]) -> Set[str]
54
+ def convert_extras (extras : Optional [str ]) -> Set [str ]:
57
55
if not extras :
58
56
return set ()
59
57
return Requirement ("placeholder" + extras .lower ()).extras
60
58
61
59
62
- def parse_editable (editable_req ):
63
- # type: (str) -> Tuple[Optional[str], str, Set[str]]
60
+ def parse_editable (editable_req : str ) -> Tuple [Optional [str ], str , Set [str ]]:
64
61
"""Parses an editable requirement into:
65
62
- a requirement name
66
63
- an URL
@@ -131,8 +128,7 @@ def parse_editable(editable_req):
131
128
return package_name , url , set ()
132
129
133
130
134
- def deduce_helpful_msg (req ):
135
- # type: (str) -> str
131
+ def deduce_helpful_msg (req : str ) -> str :
136
132
"""Returns helpful msg in case requirements file does not exist,
137
133
or cannot be parsed.
138
134
@@ -165,24 +161,23 @@ def deduce_helpful_msg(req):
165
161
class RequirementParts :
166
162
def __init__ (
167
163
self ,
168
- requirement , # type : Optional[Requirement]
169
- link , # type : Optional[Link]
170
- markers , # type : Optional[Marker]
171
- extras , # type : Set[str]
164
+ requirement : Optional [Requirement ],
165
+ link : Optional [Link ],
166
+ markers : Optional [Marker ],
167
+ extras : Set [str ],
172
168
):
173
169
self .requirement = requirement
174
170
self .link = link
175
171
self .markers = markers
176
172
self .extras = extras
177
173
178
174
179
- def parse_req_from_editable (editable_req ):
180
- # type: (str) -> RequirementParts
175
+ def parse_req_from_editable (editable_req : str ) -> RequirementParts :
181
176
name , url , extras_override = parse_editable (editable_req )
182
177
183
178
if name is not None :
184
179
try :
185
- req = Requirement (name ) # type: Optional[Requirement]
180
+ req : Optional [ Requirement ] = Requirement (name )
186
181
except InvalidRequirement :
187
182
raise InstallationError (f"Invalid requirement: '{ name } '" )
188
183
else :
@@ -197,15 +192,14 @@ def parse_req_from_editable(editable_req):
197
192
198
193
199
194
def install_req_from_editable (
200
- editable_req , # type: str
201
- comes_from = None , # type: Optional[Union[InstallRequirement, str]]
202
- use_pep517 = None , # type: Optional[bool]
203
- isolated = False , # type: bool
204
- options = None , # type: Optional[Dict[str, Any]]
205
- constraint = False , # type: bool
206
- user_supplied = False , # type: bool
207
- ):
208
- # type: (...) -> InstallRequirement
195
+ editable_req : str ,
196
+ comes_from : Optional [Union [InstallRequirement , str ]] = None ,
197
+ use_pep517 : Optional [bool ] = None ,
198
+ isolated : bool = False ,
199
+ options : Optional [Dict [str , Any ]] = None ,
200
+ constraint : bool = False ,
201
+ user_supplied : bool = False ,
202
+ ) -> InstallRequirement :
209
203
210
204
parts = parse_req_from_editable (editable_req )
211
205
@@ -225,8 +219,7 @@ def install_req_from_editable(
225
219
)
226
220
227
221
228
- def _looks_like_path (name ):
229
- # type: (str) -> bool
222
+ def _looks_like_path (name : str ) -> bool :
230
223
"""Checks whether the string "looks like" a path on the filesystem.
231
224
232
225
This does not check whether the target actually exists, only judge from the
@@ -245,8 +238,7 @@ def _looks_like_path(name):
245
238
return False
246
239
247
240
248
- def _get_url_from_path (path , name ):
249
- # type: (str, str) -> Optional[str]
241
+ def _get_url_from_path (path : str , name : str ) -> Optional [str ]:
250
242
"""
251
243
First, it checks whether a provided path is an installable directory. If it
252
244
is, returns the path.
@@ -279,8 +271,7 @@ def _get_url_from_path(path, name):
279
271
return path_to_url (path )
280
272
281
273
282
- def parse_req_from_line (name , line_source ):
283
- # type: (str, Optional[str]) -> RequirementParts
274
+ def parse_req_from_line (name : str , line_source : Optional [str ]) -> RequirementParts :
284
275
if is_url (name ):
285
276
marker_sep = '; '
286
277
else :
@@ -329,8 +320,7 @@ def parse_req_from_line(name, line_source):
329
320
330
321
extras = convert_extras (extras_as_string )
331
322
332
- def with_source (text ):
333
- # type: (str) -> str
323
+ def with_source (text : str ) -> str :
334
324
if not line_source :
335
325
return text
336
326
return f'{ text } (from { line_source } )'
@@ -366,24 +356,23 @@ def _parse_req_string(req_as_string: str) -> Requirement:
366
356
return req
367
357
368
358
if req_as_string is not None :
369
- req = _parse_req_string (req_as_string ) # type: Optional[Requirement]
359
+ req : Optional [ Requirement ] = _parse_req_string (req_as_string )
370
360
else :
371
361
req = None
372
362
373
363
return RequirementParts (req , link , markers , extras )
374
364
375
365
376
366
def install_req_from_line (
377
- name , # type: str
378
- comes_from = None , # type: Optional[Union[str, InstallRequirement]]
379
- use_pep517 = None , # type: Optional[bool]
380
- isolated = False , # type: bool
381
- options = None , # type: Optional[Dict[str, Any]]
382
- constraint = False , # type: bool
383
- line_source = None , # type: Optional[str]
384
- user_supplied = False , # type: bool
385
- ):
386
- # type: (...) -> InstallRequirement
367
+ name : str ,
368
+ comes_from : Optional [Union [str , InstallRequirement ]] = None ,
369
+ use_pep517 : Optional [bool ] = None ,
370
+ isolated : bool = False ,
371
+ options : Optional [Dict [str , Any ]] = None ,
372
+ constraint : bool = False ,
373
+ line_source : Optional [str ] = None ,
374
+ user_supplied : bool = False ,
375
+ ) -> InstallRequirement :
387
376
"""Creates an InstallRequirement from a name, which might be a
388
377
requirement, directory containing 'setup.py', filename, or URL.
389
378
@@ -405,13 +394,12 @@ def install_req_from_line(
405
394
406
395
407
396
def install_req_from_req_string (
408
- req_string , # type: str
409
- comes_from = None , # type: Optional[InstallRequirement]
410
- isolated = False , # type: bool
411
- use_pep517 = None , # type: Optional[bool]
412
- user_supplied = False , # type: bool
413
- ):
414
- # type: (...) -> InstallRequirement
397
+ req_string : str ,
398
+ comes_from : Optional [InstallRequirement ] = None ,
399
+ isolated : bool = False ,
400
+ use_pep517 : Optional [bool ] = None ,
401
+ user_supplied : bool = False ,
402
+ ) -> InstallRequirement :
415
403
try :
416
404
req = Requirement (req_string )
417
405
except InvalidRequirement :
@@ -440,12 +428,11 @@ def install_req_from_req_string(
440
428
441
429
442
430
def install_req_from_parsed_requirement (
443
- parsed_req , # type: ParsedRequirement
444
- isolated = False , # type: bool
445
- use_pep517 = None , # type: Optional[bool]
446
- user_supplied = False , # type: bool
447
- ):
448
- # type: (...) -> InstallRequirement
431
+ parsed_req : ParsedRequirement ,
432
+ isolated : bool = False ,
433
+ use_pep517 : Optional [bool ] = None ,
434
+ user_supplied : bool = False ,
435
+ ) -> InstallRequirement :
449
436
if parsed_req .is_editable :
450
437
req = install_req_from_editable (
451
438
parsed_req .requirement ,
@@ -470,8 +457,9 @@ def install_req_from_parsed_requirement(
470
457
return req
471
458
472
459
473
- def install_req_from_link_and_ireq (link , ireq ):
474
- # type: (Link, InstallRequirement) -> InstallRequirement
460
+ def install_req_from_link_and_ireq (
461
+ link : Link , ireq : InstallRequirement
462
+ ) -> InstallRequirement :
475
463
return InstallRequirement (
476
464
req = ireq .req ,
477
465
comes_from = ireq .comes_from ,
0 commit comments