Skip to content

Commit

Permalink
fix: resolve requirements paths relative to the requirement file they…
Browse files Browse the repository at this point in the history
… are specified in (#2422)
  • Loading branch information
mattem authored Nov 23, 2023
1 parent a339412 commit 4f80ef8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/2422.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resolve `-r` requirements paths relative to the requirement file they are specified in
9 changes: 5 additions & 4 deletions src/pdm/formats/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _clean_line(self, line: str) -> str:
return ""
return line.split(" #", 1)[0].strip()

def _parse_line(self, line: str) -> None:
def _parse_line(self, filename: str, line: str) -> None:
if not line.startswith("-"):
# Starts with a requirement, just ignore all per-requirement options
req_string = line.split(" -", 1)[0].strip()
Expand All @@ -76,7 +76,8 @@ def _parse_line(self, line: str) -> None:
if args.editable:
self.requirements.append(parse_requirement(" ".join(args.editable), True))
if args.requirement:
self.parse(args.requirement)
referenced_requirements = str(Path(filename).parent.joinpath(args.requirement))
self.parse(referenced_requirements)

def parse(self, filename: str) -> None:
with open(filename, encoding="utf-8") as f:
Expand All @@ -86,10 +87,10 @@ def parse(self, filename: str) -> None:
this_line += line[:-1].rstrip() + " "
continue
this_line += line
self._parse_line(this_line)
self._parse_line(filename, this_line)
this_line = ""
if this_line:
self._parse_line(this_line)
self._parse_line(filename, this_line)


def check_fingerprint(project: Project, filename: PathLike) -> bool:
Expand Down

0 comments on commit 4f80ef8

Please sign in to comment.