Skip to content

Commit

Permalink
Report detailed information about invalid requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed May 20, 2024
1 parent 530df8a commit ed91272
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/12713.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Report informative messages about invalid requirements.
12 changes: 6 additions & 6 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ def parse_req_from_editable(editable_req: str) -> RequirementParts:
if name is not None:
try:
req: Optional[Requirement] = Requirement(name)
except InvalidRequirement:
raise InstallationError(f"Invalid requirement: '{name}'")
except InvalidRequirement as exc:
raise InstallationError(f"Invalid requirement: {name!r}: {exc}")
else:
req = None

Expand Down Expand Up @@ -360,7 +360,7 @@ def with_source(text: str) -> str:
def _parse_req_string(req_as_string: str) -> Requirement:
try:
return get_requirement(req_as_string)
except InvalidRequirement:
except InvalidRequirement as exc:
if os.path.sep in req_as_string:
add_msg = "It looks like a path."
add_msg += deduce_helpful_msg(req_as_string)
Expand All @@ -370,7 +370,7 @@ def _parse_req_string(req_as_string: str) -> Requirement:
add_msg = "= is not a valid operator. Did you mean == ?"
else:
add_msg = ""
msg = with_source(f"Invalid requirement: {req_as_string!r}")
msg = with_source(f"Invalid requirement: {req_as_string!r}: {exc}")
if add_msg:
msg += f"\nHint: {add_msg}"
raise InstallationError(msg)
Expand Down Expand Up @@ -429,8 +429,8 @@ def install_req_from_req_string(
) -> InstallRequirement:
try:
req = get_requirement(req_string)
except InvalidRequirement:
raise InstallationError(f"Invalid requirement: '{req_string}'")
except InvalidRequirement as exc:
raise InstallationError(f"Invalid requirement: {req_string!r}: {exc}")

domains_not_allowed = [
PyPI.file_storage_domain,
Expand Down

0 comments on commit ed91272

Please sign in to comment.