Skip to content

Commit

Permalink
Fix a bug of dependency graph missing deps (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored May 27, 2022
1 parent 0bf881f commit e519a07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions news/1097.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that dependencies missing from the dep graph when they are depended by a requirement with extras.
5 changes: 4 additions & 1 deletion pdm/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def add_package(key: str, dist: Distribution | None) -> Package:
requirements = (
parse_requirement(r)
for r in filter_requirements_with_extras(
dist.metadata["Name"], dist.requires or [], extras # type: ignore
cast(str, dist.metadata["Name"]),
dist.requires or [],
extras,
include_default=True,
)
)
for req in requirements:
Expand Down
20 changes: 14 additions & 6 deletions pdm/models/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,10 @@ def _build_url_from_req_dict(name: str, url: str, req_dict: RequirementDict) ->


def filter_requirements_with_extras(
project_name: str, requirement_lines: list[str], extras: Sequence[str]
project_name: str,
requirement_lines: list[str],
extras: Sequence[str],
include_default: bool = False,
) -> list[str]:
"""Filter the requirements with extras.
If extras are given, return those with matching extra markers.
Expand All @@ -454,13 +457,18 @@ def filter_requirements_with_extras(
for req in requirement_lines:
_r = parse_requirement(req)
if _r.marker:
elements, rest = split_marker_extras(str(_r.marker))
if elements:
extras_in_meta.update(elements)
req_extras, rest = split_marker_extras(str(_r.marker))
if req_extras:
extras_in_meta.update(req_extras)
_r.marker = Marker(rest) if rest else None
else:
elements = set()
if extras and not elements.isdisjoint(extras) or not (extras or elements):
req_extras = set()
if (
req_extras
and not req_extras.isdisjoint(extras)
or not req_extras
and (include_default or not extras)
):
result.append(_r.as_line())

extras_not_found = [e for e in extras if e not in extras_in_meta]
Expand Down

0 comments on commit e519a07

Please sign in to comment.