Skip to content

Commit

Permalink
fix(#2417): provide context when parsing requirement fails
Browse files Browse the repository at this point in the history
Fix #2417

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Nov 22, 2023
1 parent cc3e908 commit 3eddfbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/2417.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Provide information of the original line when parsing requirement fails.
8 changes: 4 additions & 4 deletions src/pdm/models/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def create(cls: type[T], **kwargs: Any) -> T:
try:
kwargs["marker"] = get_marker(kwargs["marker"])
except InvalidMarker as e:
raise RequirementError("Invalid marker: %s" % str(e)) from None
raise RequirementError(f"Invalid marker: {e}") from None
if "extras" in kwargs and isinstance(kwargs["extras"], str):
kwargs["extras"] = tuple(e.strip() for e in kwargs["extras"][1:-1].split(","))
version = kwargs.pop("version", "")
Expand Down Expand Up @@ -497,10 +497,10 @@ def parse_requirement(line: str, editable: bool = False) -> Requirement:
except InvalidRequirement as e:
m = _file_req_re.match(line)
if m is None:
raise RequirementError(str(e)) from None
raise RequirementError(f"{line}: {e}") from None
args = m.groupdict()
if not line.startswith(".") and not args["url"] and args["path"] and not os.path.exists(args["path"]):
raise RequirementError(str(e)) from None
raise RequirementError(f"{line}: {e}") from None
r = FileRequirement.create(**args)
else:
r = Requirement.from_pkg_requirement(pkg_req)
Expand All @@ -514,5 +514,5 @@ def parse_requirement(line: str, editable: bool = False) -> Requirement:
assert isinstance(r, FileRequirement)
r.editable = True
else:
raise RequirementError("Editable requirement is only supported for VCS link or local directory.")
raise RequirementError(f"{line}: Editable requirement is only supported for VCS link or local directory.")
return r

0 comments on commit 3eddfbc

Please sign in to comment.