Skip to content

Commit ec8bf2c

Browse files
committed
Clean up source location message creation.
1 parent c3e6329 commit ec8bf2c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/pip/_internal/req/constructors.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ def install_req_from_line(
336336
extras = Requirement("placeholder" + extras_as_string.lower()).extras
337337
else:
338338
extras = ()
339+
340+
def with_source(text):
341+
if not line_source:
342+
return text
343+
return '{} (from {})'.format(text, line_source)
344+
339345
if req_as_string is not None:
340346
try:
341347
req = Requirement(req_as_string)
@@ -348,12 +354,8 @@ def install_req_from_line(
348354
add_msg = "= is not a valid operator. Did you mean == ?"
349355
else:
350356
add_msg = ''
351-
if line_source is None:
352-
source = ''
353-
else:
354-
source = ' (from {})'.format(line_source)
355-
msg = (
356-
'Invalid requirement: {!r}{}'.format(req_as_string, source)
357+
msg = with_source(
358+
'Invalid requirement: {!r}'.format(req_as_string)
357359
)
358360
if add_msg:
359361
msg += '\nHint: {}'.format(add_msg)

0 commit comments

Comments
 (0)