Skip to content

Clean up req.constructors.install_req_from_line #7025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -332,10 +340,13 @@ 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:
return text
return '{} (from {})'.format(text, line_source)

if req_as_string is not None:
try:
req = Requirement(req_as_string)
Expand All @@ -348,12 +359,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)
Expand Down