@@ -70,6 +70,14 @@ def _strip_extras(path):
70
70
return path_no_extras , extras
71
71
72
72
73
+ def convert_extras (extras ):
74
+ # type: (Optional[str]) -> Set[str]
75
+ if extras :
76
+ return Requirement ("placeholder" + extras .lower ()).extras
77
+ else :
78
+ return set ()
79
+
80
+
73
81
def parse_editable (editable_req ):
74
82
# type: (str) -> Tuple[Optional[str], str, Optional[Set[str]]]
75
83
"""Parses an editable requirement into:
@@ -328,10 +336,13 @@ def install_req_from_line(
328
336
else :
329
337
req_as_string = name
330
338
331
- if extras_as_string :
332
- extras = Requirement ("placeholder" + extras_as_string .lower ()).extras
333
- else :
334
- extras = ()
339
+ extras = convert_extras (extras_as_string )
340
+
341
+ def with_source (text ):
342
+ if not line_source :
343
+ return text
344
+ return '{} (from {})' .format (text , line_source )
345
+
335
346
if req_as_string is not None :
336
347
try :
337
348
req = Requirement (req_as_string )
@@ -344,12 +355,8 @@ def install_req_from_line(
344
355
add_msg = "= is not a valid operator. Did you mean == ?"
345
356
else :
346
357
add_msg = ''
347
- if line_source is None :
348
- source = ''
349
- else :
350
- source = ' (from {})' .format (line_source )
351
- msg = (
352
- 'Invalid requirement: {!r}{}' .format (req_as_string , source )
358
+ msg = with_source (
359
+ 'Invalid requirement: {!r}' .format (req_as_string )
353
360
)
354
361
if add_msg :
355
362
msg += '\n Hint: {}' .format (add_msg )
0 commit comments