Skip to content

Commit

Permalink
Allow to get the full dependency list
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-costas committed Jul 4, 2022
1 parent f077f0c commit 8ca02dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion craft_parts/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,22 @@ def has_overlay(self) -> bool:
)


def get_dependencies_full(part: Part, part_list: List[Part]) -> List[str]:
"""Return the list of parts that this part depends on, taking
into account the groups.
"""
dep_list = []
part_names = [p.name for p in part_list]
for dep in part.dependencies:
if dep in part_names:
dep_list.append(dep)
continue
for other in part_list:
if (dep in other.groups) and (other.name not in dep_list):
dep_list.append(other.name)
return dep_list


def part_by_name(name: str, part_list: List[Part]) -> Part:
"""Obtain the part with the given name from the part list.
Expand Down Expand Up @@ -371,7 +387,7 @@ def part_dependencies(
:returns: The set of parts the given part depends on.
"""
dependency_names = set(part.dependencies)
dependency_names = set(get_dependencies_full(part, part_list))
dependencies = {p for p in part_list if p.name in dependency_names}

if recursive:
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ def test_sort_parts_group(self):
x = parts.sort_parts([p1, p2, p3])
assert x == [p3, p2, p1]

def test_find_dependencies_with_groups(self):
p1 = Part("baz", {"after": ["foogroup"]})
p2 = Part("bar", {"after": ["foo"], "groups": ["foogroup"]})
p3 = Part("foo", {"groups": ["foogroup"]})

part_list = [p1, p2, p3]
assert parts.get_dependencies_full(p1, part_list) == ['bar', 'foo']


class TestPartUnmarshal:
"""Verify data unmarshaling on part creation."""
Expand Down

0 comments on commit 8ca02dc

Please sign in to comment.