From ec8bf2cc2276c0945e0c3e47284486c0e38a3e42 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Sun, 15 Sep 2019 20:47:11 -0400 Subject: [PATCH 1/2] Clean up source location message creation. --- src/pip/_internal/req/constructors.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index 8142c22f3f6..129e3830326 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -336,6 +336,12 @@ def install_req_from_line( extras = Requirement("placeholder" + extras_as_string.lower()).extras else: extras = () + + def with_source(text): + if not line_source: + return text + return '{} (from {})'.format(text, line_source) + if req_as_string is not None: try: req = Requirement(req_as_string) @@ -348,12 +354,8 @@ def install_req_from_line( add_msg = "= is not a valid operator. Did you mean == ?" else: add_msg = '' - if line_source is None: - source = '' - else: - source = ' (from {})'.format(line_source) - msg = ( - 'Invalid requirement: {!r}{}'.format(req_as_string, source) + msg = with_source( + 'Invalid requirement: {!r}'.format(req_as_string) ) if add_msg: msg += '\nHint: {}'.format(add_msg) From 05552610874e139e224425c754c5276d099a3851 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Sun, 15 Sep 2019 20:49:45 -0400 Subject: [PATCH 2/2] Move extra conversion to function. --- src/pip/_internal/req/constructors.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index 129e3830326..6122f27e650 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -74,6 +74,14 @@ def _strip_extras(path): return path_no_extras, extras +def convert_extras(extras): + # type: (Optional[str]) -> Set[str] + if extras: + return Requirement("placeholder" + extras.lower()).extras + else: + return set() + + def parse_editable(editable_req): # type: (str) -> Tuple[Optional[str], str, Optional[Set[str]]] """Parses an editable requirement into: @@ -332,10 +340,7 @@ def install_req_from_line( else: req_as_string = name - if extras_as_string: - extras = Requirement("placeholder" + extras_as_string.lower()).extras - else: - extras = () + extras = convert_extras(extras_as_string) def with_source(text): if not line_source: