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)

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
mattem authored and frostming committed Nov 23, 2023
1 parent a339412 commit 837e7d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/2422.bugfix.md
@@ -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
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
3 changes: 1 addition & 2 deletions src/pdm/installers/installers.py
Expand Up @@ -73,8 +73,7 @@ def _is_namespace_package(root: str) -> bool:


def _create_symlinks_recursively(source: str, destination: str) -> Iterable[str]:
"""Create symlinks recursively from source to destination.
Caveats: This don't work for pkgutil or pkg_resources namespace packages.
"""Create symlinks recursively from source to destination. In the following ways:
package <-- link
__init__.py
namespace_package <-- mkdir
Expand Down

0 comments on commit 837e7d0

Please sign in to comment.