From 03194936758dbdee0b579b88537edcc5ec413ccc Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Mon, 7 Aug 2023 16:33:08 -0500 Subject: [PATCH] Track dependency categories on recursive dependencies 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. --- colcon_core/package_descriptor.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/colcon_core/package_descriptor.py b/colcon_core/package_descriptor.py index baf6022d..3505b1b4 100644 --- a/colcon_core/package_descriptor.py +++ b/colcon_core/package_descriptor.py @@ -71,16 +71,20 @@ 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 not isinstance(dependency, DependencyDescriptor): + 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,