Skip to content

Commit 83780a2

Browse files
authored
Merge pull request #7025 from chrahunt/refactor-1
Clean up req.constructors.install_req_from_line
2 parents b0a6428 + 0555261 commit 83780a2

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/pip/_internal/req/constructors.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ def _strip_extras(path):
7070
return path_no_extras, extras
7171

7272

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+
7381
def parse_editable(editable_req):
7482
# type: (str) -> Tuple[Optional[str], str, Optional[Set[str]]]
7583
"""Parses an editable requirement into:
@@ -328,10 +336,13 @@ def install_req_from_line(
328336
else:
329337
req_as_string = name
330338

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+
335346
if req_as_string is not None:
336347
try:
337348
req = Requirement(req_as_string)
@@ -344,12 +355,8 @@ def install_req_from_line(
344355
add_msg = "= is not a valid operator. Did you mean == ?"
345356
else:
346357
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)
353360
)
354361
if add_msg:
355362
msg += '\nHint: {}'.format(add_msg)

0 commit comments

Comments
 (0)