Skip to content

Commit

Permalink
Track dependency categories on recursive dependencies
Browse files Browse the repository at this point in the history
When enumerating the recursive dependencies for a package descriptor,
track which dependency categories the dependency appears to be a part
of. This information can be used later to drop certain dependencies or
inform a developer of the context around a relationship.
  • Loading branch information
cottsay committed Aug 10, 2023
1 parent 7b70e61 commit 9d80cd5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions colcon_core/package_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,22 @@ def get_dependencies(self, *, categories=None):
:raises AssertionError: if the package name is listed as a dependency
"""
dependencies = set()
categories_by_dependency = defaultdict(list)
if categories is None:
categories = self.dependencies.keys()
for category in sorted(categories):
dependencies |= self.dependencies[category]
for dependency in self.dependencies[category]:
categories_by_dependency[dependency].append(category)
for dependency, categories in categories_by_dependency.items():
if isinstance(dependency, DependencyDescriptor):
dependency = deepcopy(dependency)

Check warning on line 82 in colcon_core/package_descriptor.py

View check run for this annotation

Codecov / codecov/patch

colcon_core/package_descriptor.py#L82

Added line #L82 was not covered by tests
else:
dependency = DependencyDescriptor(dependency)
dependency.metadata['categories'] = categories
dependencies.add(dependency)
assert self.name not in dependencies, \
f"The package '{self.name}' has a dependency with the same name"
return {
(DependencyDescriptor(d)
if not isinstance(d, DependencyDescriptor) else d)
for d in dependencies}
return dependencies

def get_recursive_dependencies(
self, descriptors, direct_categories=None, recursive_categories=None,
Expand Down

0 comments on commit 9d80cd5

Please sign in to comment.