Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track dependency categories on recursive dependencies #570

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions colcon_core/package_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,26 @@ 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):
# duplicate the descriptor and metadata
dependency = deepcopy(dependency)
else:
dependency = DependencyDescriptor(dependency)
# note that the category list is not merged when a dependency
# appears multiple times in a package's tree, and the most shallow
# instance prevails.
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 Expand Up @@ -127,8 +137,7 @@ def get_recursive_dependencies(
for d in descs:
queue |= d.get_dependencies(
categories=recursive_categories)
# duplicate the descriptor and metadata and add the depth
dep = deepcopy(dep)
# add the depth
dep.metadata['depth'] = depth
# add dependency to result set
dependencies.add(dep)
Expand Down
7 changes: 4 additions & 3 deletions test/test_package_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from pathlib import Path

from colcon_core.dependency_descriptor import DependencyDescriptor
from colcon_core.package_descriptor import PackageDescriptor
import pytest

Expand Down Expand Up @@ -57,9 +58,9 @@ def test_get_recursive_dependencies():

d1 = PackageDescriptor('/other/path')
d1.name = 'B'
d1.dependencies['build'].add('e')
d1.dependencies['run'].add('F')
d1.dependencies['test'].add('G')
d1.dependencies['build'].add(DependencyDescriptor('e'))
d1.dependencies['run'].add(DependencyDescriptor('F'))
d1.dependencies['test'].add(DependencyDescriptor('G'))

d2 = PackageDescriptor('/another/path')
d2.name = 'd'
Expand Down