From 596949e63f4ff16d8a92bbdb7387dfceb83692d8 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 22 May 2024 13:39:53 -0700 Subject: [PATCH 1/3] Support alternate group names in get_*_extensions These functions are brief, but it would be nice not to have to duplicate them in other colcon packages which re-use the same extension frameworks. --- colcon_core/argument_parser/__init__.py | 4 ++-- colcon_core/environment/__init__.py | 4 ++-- colcon_core/event_handler/__init__.py | 4 ++-- colcon_core/executor/__init__.py | 4 ++-- colcon_core/package_augmentation/__init__.py | 4 ++-- colcon_core/package_discovery/__init__.py | 4 ++-- colcon_core/package_identification/__init__.py | 4 ++-- colcon_core/package_selection/__init__.py | 4 ++-- colcon_core/prefix_path/__init__.py | 4 ++-- colcon_core/shell/__init__.py | 9 +++++---- colcon_core/task/python/test/__init__.py | 7 ++++--- colcon_core/verb/__init__.py | 4 ++-- 12 files changed, 29 insertions(+), 27 deletions(-) diff --git a/colcon_core/argument_parser/__init__.py b/colcon_core/argument_parser/__init__.py index 44f743133..8a6128b37 100644 --- a/colcon_core/argument_parser/__init__.py +++ b/colcon_core/argument_parser/__init__.py @@ -42,7 +42,7 @@ def decorate_argument_parser(self, *, parser): raise NotImplementedError() -def get_argument_parser_extensions(): +def get_argument_parser_extensions(*, group_name=__name__): """ Get the available argument parser extensions. @@ -50,7 +50,7 @@ def get_argument_parser_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.ARGUMENT_PARSER_DECORATOR_NAME = name return order_extensions_by_priority(extensions) diff --git a/colcon_core/environment/__init__.py b/colcon_core/environment/__init__.py index d57adbf3b..3ab923bae 100644 --- a/colcon_core/environment/__init__.py +++ b/colcon_core/environment/__init__.py @@ -47,7 +47,7 @@ def create_environment_hooks(self, prefix_path, pkg_name): raise NotImplementedError() -def get_environment_extensions(): +def get_environment_extensions(*, group_name=__name__): """ Get the available environment extensions. @@ -55,7 +55,7 @@ def get_environment_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name in list(extensions.keys()): extension = extensions[name] extension.ENVIRONMENT_NAME = name diff --git a/colcon_core/event_handler/__init__.py b/colcon_core/event_handler/__init__.py index a51756c5b..435cf9e1e 100644 --- a/colcon_core/event_handler/__init__.py +++ b/colcon_core/event_handler/__init__.py @@ -44,7 +44,7 @@ def __call__(self, event): raise NotImplementedError() -def get_event_handler_extensions(*, context): +def get_event_handler_extensions(*, context, group_name=__name__): """ Get the available event handler extensions. @@ -52,7 +52,7 @@ def get_event_handler_extensions(*, context): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.EVENT_HANDLER_NAME = name extension.context = context diff --git a/colcon_core/executor/__init__.py b/colcon_core/executor/__init__.py index aca035758..fb05bcf5f 100644 --- a/colcon_core/executor/__init__.py +++ b/colcon_core/executor/__init__.py @@ -197,7 +197,7 @@ def _flush(self): self._event_controller.flush() -def get_executor_extensions(): +def get_executor_extensions(*, group_name=__name__): """ Get the available executor extensions. @@ -206,7 +206,7 @@ def get_executor_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.EXECUTOR_NAME = name return order_extensions_grouped_by_priority(extensions) diff --git a/colcon_core/package_augmentation/__init__.py b/colcon_core/package_augmentation/__init__.py index 3b579292f..a6058921a 100644 --- a/colcon_core/package_augmentation/__init__.py +++ b/colcon_core/package_augmentation/__init__.py @@ -65,7 +65,7 @@ def augment_package( raise NotImplementedError() -def get_package_augmentation_extensions(): +def get_package_augmentation_extensions(*, group_name=__name__): """ Get the available package augmentation extensions. @@ -73,7 +73,7 @@ def get_package_augmentation_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_AUGMENTATION_NAME = name return order_extensions_by_priority(extensions) diff --git a/colcon_core/package_discovery/__init__.py b/colcon_core/package_discovery/__init__.py index fc60f1470..c2e2f0e1e 100644 --- a/colcon_core/package_discovery/__init__.py +++ b/colcon_core/package_discovery/__init__.py @@ -84,7 +84,7 @@ def discover(self, *, args, identification_extensions): raise NotImplementedError() -def get_package_discovery_extensions(): +def get_package_discovery_extensions(*, group_name=__name__): """ Get the available package discovery extensions. @@ -92,7 +92,7 @@ def get_package_discovery_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_DISCOVERY_NAME = name return order_extensions_by_priority(extensions) diff --git a/colcon_core/package_identification/__init__.py b/colcon_core/package_identification/__init__.py index 11e17d73f..9bb561570 100644 --- a/colcon_core/package_identification/__init__.py +++ b/colcon_core/package_identification/__init__.py @@ -64,7 +64,7 @@ def identify(self, desc: PackageDescriptor): raise NotImplementedError() -def get_package_identification_extensions(): +def get_package_identification_extensions(*, group_name=__name__): """ Get the available package identification extensions. @@ -73,7 +73,7 @@ def get_package_identification_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_IDENTIFICATION_NAME = name return order_extensions_grouped_by_priority(extensions) diff --git a/colcon_core/package_selection/__init__.py b/colcon_core/package_selection/__init__.py index 6b1bdc9f0..c5cd923fc 100644 --- a/colcon_core/package_selection/__init__.py +++ b/colcon_core/package_selection/__init__.py @@ -85,7 +85,7 @@ def add_arguments(parser): _add_package_selection_arguments(parser) -def get_package_selection_extensions(): +def get_package_selection_extensions(*, group_name=__name__): """ Get the available package selection extensions. @@ -93,7 +93,7 @@ def get_package_selection_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_SELECTION_NAME = name return order_extensions_by_priority(extensions) diff --git a/colcon_core/prefix_path/__init__.py b/colcon_core/prefix_path/__init__.py index 15aae0b2e..ca4f58eff 100644 --- a/colcon_core/prefix_path/__init__.py +++ b/colcon_core/prefix_path/__init__.py @@ -40,7 +40,7 @@ def extend_prefix_path(self, paths): raise NotImplementedError() -def get_prefix_path_extensions(): +def get_prefix_path_extensions(*, group_name=__name__): """ Get the available prefix path extensions. @@ -49,7 +49,7 @@ def get_prefix_path_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PREFIX_PATH_NAME = name return order_extensions_grouped_by_priority(extensions) diff --git a/colcon_core/shell/__init__.py b/colcon_core/shell/__init__.py index faa103ff7..05539e9e5 100644 --- a/colcon_core/shell/__init__.py +++ b/colcon_core/shell/__init__.py @@ -273,7 +273,7 @@ async def generate_command_environment( raise NotImplementedError() -def get_shell_extensions(): +def get_shell_extensions(*, group_name=__name__): """ Get the available shell extensions. @@ -282,7 +282,7 @@ def get_shell_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.SHELL_NAME = name return order_extensions_grouped_by_priority(extensions) @@ -593,7 +593,7 @@ def find_installed_packages(self, install_base: Path): raise NotImplementedError() -def get_find_installed_packages_extensions(): +def get_find_installed_packages_extensions(*, group_name=__name__): """ Get the available package identification extensions. @@ -602,7 +602,8 @@ def get_find_installed_packages_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__ + '.find_installed_packages') + extensions = instantiate_extensions( + group_name + '.find_installed_packages') for name, extension in extensions.items(): extension.PACKAGE_IDENTIFICATION_NAME = name return order_extensions_grouped_by_priority(extensions) diff --git a/colcon_core/task/python/test/__init__.py b/colcon_core/task/python/test/__init__.py index 74a5ed2b8..8ccb6964f 100644 --- a/colcon_core/task/python/test/__init__.py +++ b/colcon_core/task/python/test/__init__.py @@ -137,7 +137,9 @@ async def step(self): raise NotImplementedError() -def get_python_testing_step_extensions(): +def get_python_testing_step_extensions( + *, group_name='colcon_core.python_testing', +): """ Get the available Python testing step extensions. @@ -145,8 +147,7 @@ def get_python_testing_step_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions( - 'colcon_core.python_testing', unique_instance=False) + extensions = instantiate_extensions(group_name, unique_instance=False) for name in list(extensions.keys()): extension = extensions[name] extension.STEP_TYPE = name diff --git a/colcon_core/verb/__init__.py b/colcon_core/verb/__init__.py index 640dc218f..fbf3864b8 100644 --- a/colcon_core/verb/__init__.py +++ b/colcon_core/verb/__init__.py @@ -48,7 +48,7 @@ def main(self, *, context): raise NotImplementedError() -def get_verb_extensions(): +def get_verb_extensions(*, group_name=__name__): """ Get the available verb extensions. @@ -56,7 +56,7 @@ def get_verb_extensions(): :rtype: OrderedDict """ - extensions = instantiate_extensions(__name__) + extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.VERB_NAME = name return order_extensions_by_name(extensions) From d7b09f9c5c3e83ca4274980d280957c563263ef4 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 22 May 2024 13:48:25 -0700 Subject: [PATCH 2/3] Use 'None' as argument default --- colcon_core/argument_parser/__init__.py | 4 +++- colcon_core/environment/__init__.py | 4 +++- colcon_core/event_handler/__init__.py | 4 +++- colcon_core/executor/__init__.py | 4 +++- colcon_core/package_augmentation/__init__.py | 4 +++- colcon_core/package_discovery/__init__.py | 4 +++- colcon_core/package_identification/__init__.py | 4 +++- colcon_core/package_selection/__init__.py | 4 +++- colcon_core/prefix_path/__init__.py | 4 +++- colcon_core/shell/__init__.py | 8 ++++++-- colcon_core/verb/__init__.py | 4 +++- 11 files changed, 36 insertions(+), 12 deletions(-) diff --git a/colcon_core/argument_parser/__init__.py b/colcon_core/argument_parser/__init__.py index 8a6128b37..21f069489 100644 --- a/colcon_core/argument_parser/__init__.py +++ b/colcon_core/argument_parser/__init__.py @@ -42,7 +42,7 @@ def decorate_argument_parser(self, *, parser): raise NotImplementedError() -def get_argument_parser_extensions(*, group_name=__name__): +def get_argument_parser_extensions(*, group_name=None): """ Get the available argument parser extensions. @@ -50,6 +50,8 @@ def get_argument_parser_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.ARGUMENT_PARSER_DECORATOR_NAME = name diff --git a/colcon_core/environment/__init__.py b/colcon_core/environment/__init__.py index 3ab923bae..a7324d017 100644 --- a/colcon_core/environment/__init__.py +++ b/colcon_core/environment/__init__.py @@ -47,7 +47,7 @@ def create_environment_hooks(self, prefix_path, pkg_name): raise NotImplementedError() -def get_environment_extensions(*, group_name=__name__): +def get_environment_extensions(*, group_name=None): """ Get the available environment extensions. @@ -55,6 +55,8 @@ def get_environment_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name in list(extensions.keys()): extension = extensions[name] diff --git a/colcon_core/event_handler/__init__.py b/colcon_core/event_handler/__init__.py index 435cf9e1e..437894626 100644 --- a/colcon_core/event_handler/__init__.py +++ b/colcon_core/event_handler/__init__.py @@ -44,7 +44,7 @@ def __call__(self, event): raise NotImplementedError() -def get_event_handler_extensions(*, context, group_name=__name__): +def get_event_handler_extensions(*, context, group_name=None): """ Get the available event handler extensions. @@ -52,6 +52,8 @@ def get_event_handler_extensions(*, context, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.EVENT_HANDLER_NAME = name diff --git a/colcon_core/executor/__init__.py b/colcon_core/executor/__init__.py index fb05bcf5f..c0bdaccf9 100644 --- a/colcon_core/executor/__init__.py +++ b/colcon_core/executor/__init__.py @@ -197,7 +197,7 @@ def _flush(self): self._event_controller.flush() -def get_executor_extensions(*, group_name=__name__): +def get_executor_extensions(*, group_name=None): """ Get the available executor extensions. @@ -206,6 +206,8 @@ def get_executor_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.EXECUTOR_NAME = name diff --git a/colcon_core/package_augmentation/__init__.py b/colcon_core/package_augmentation/__init__.py index a6058921a..e741292a1 100644 --- a/colcon_core/package_augmentation/__init__.py +++ b/colcon_core/package_augmentation/__init__.py @@ -65,7 +65,7 @@ def augment_package( raise NotImplementedError() -def get_package_augmentation_extensions(*, group_name=__name__): +def get_package_augmentation_extensions(*, group_name=None): """ Get the available package augmentation extensions. @@ -73,6 +73,8 @@ def get_package_augmentation_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_AUGMENTATION_NAME = name diff --git a/colcon_core/package_discovery/__init__.py b/colcon_core/package_discovery/__init__.py index c2e2f0e1e..c16f3b1d3 100644 --- a/colcon_core/package_discovery/__init__.py +++ b/colcon_core/package_discovery/__init__.py @@ -84,7 +84,7 @@ def discover(self, *, args, identification_extensions): raise NotImplementedError() -def get_package_discovery_extensions(*, group_name=__name__): +def get_package_discovery_extensions(*, group_name=None): """ Get the available package discovery extensions. @@ -92,6 +92,8 @@ def get_package_discovery_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_DISCOVERY_NAME = name diff --git a/colcon_core/package_identification/__init__.py b/colcon_core/package_identification/__init__.py index 9bb561570..01dd8a2ce 100644 --- a/colcon_core/package_identification/__init__.py +++ b/colcon_core/package_identification/__init__.py @@ -64,7 +64,7 @@ def identify(self, desc: PackageDescriptor): raise NotImplementedError() -def get_package_identification_extensions(*, group_name=__name__): +def get_package_identification_extensions(*, group_name=None): """ Get the available package identification extensions. @@ -73,6 +73,8 @@ def get_package_identification_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_IDENTIFICATION_NAME = name diff --git a/colcon_core/package_selection/__init__.py b/colcon_core/package_selection/__init__.py index c5cd923fc..bdbacd887 100644 --- a/colcon_core/package_selection/__init__.py +++ b/colcon_core/package_selection/__init__.py @@ -85,7 +85,7 @@ def add_arguments(parser): _add_package_selection_arguments(parser) -def get_package_selection_extensions(*, group_name=__name__): +def get_package_selection_extensions(*, group_name=None): """ Get the available package selection extensions. @@ -93,6 +93,8 @@ def get_package_selection_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PACKAGE_SELECTION_NAME = name diff --git a/colcon_core/prefix_path/__init__.py b/colcon_core/prefix_path/__init__.py index ca4f58eff..4fa34eb88 100644 --- a/colcon_core/prefix_path/__init__.py +++ b/colcon_core/prefix_path/__init__.py @@ -40,7 +40,7 @@ def extend_prefix_path(self, paths): raise NotImplementedError() -def get_prefix_path_extensions(*, group_name=__name__): +def get_prefix_path_extensions(*, group_name=None): """ Get the available prefix path extensions. @@ -49,6 +49,8 @@ def get_prefix_path_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.PREFIX_PATH_NAME = name diff --git a/colcon_core/shell/__init__.py b/colcon_core/shell/__init__.py index 05539e9e5..7924b7953 100644 --- a/colcon_core/shell/__init__.py +++ b/colcon_core/shell/__init__.py @@ -273,7 +273,7 @@ async def generate_command_environment( raise NotImplementedError() -def get_shell_extensions(*, group_name=__name__): +def get_shell_extensions(*, group_name=None): """ Get the available shell extensions. @@ -282,6 +282,8 @@ def get_shell_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.SHELL_NAME = name @@ -593,7 +595,7 @@ def find_installed_packages(self, install_base: Path): raise NotImplementedError() -def get_find_installed_packages_extensions(*, group_name=__name__): +def get_find_installed_packages_extensions(*, group_name=None): """ Get the available package identification extensions. @@ -602,6 +604,8 @@ def get_find_installed_packages_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions( group_name + '.find_installed_packages') for name, extension in extensions.items(): diff --git a/colcon_core/verb/__init__.py b/colcon_core/verb/__init__.py index fbf3864b8..49913ba16 100644 --- a/colcon_core/verb/__init__.py +++ b/colcon_core/verb/__init__.py @@ -48,7 +48,7 @@ def main(self, *, context): raise NotImplementedError() -def get_verb_extensions(*, group_name=__name__): +def get_verb_extensions(*, group_name=None): """ Get the available verb extensions. @@ -56,6 +56,8 @@ def get_verb_extensions(*, group_name=__name__): :rtype: OrderedDict """ + if group_name is None: + group_name = __name__ extensions = instantiate_extensions(group_name) for name, extension in extensions.items(): extension.VERB_NAME = name From e0d08aa376390796e46d7609d3df70902f377269 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 22 May 2024 13:50:16 -0700 Subject: [PATCH 3/3] fixup! Use 'None' as argument default --- colcon_core/task/python/test/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/colcon_core/task/python/test/__init__.py b/colcon_core/task/python/test/__init__.py index 8ccb6964f..a01ec4784 100644 --- a/colcon_core/task/python/test/__init__.py +++ b/colcon_core/task/python/test/__init__.py @@ -137,9 +137,7 @@ async def step(self): raise NotImplementedError() -def get_python_testing_step_extensions( - *, group_name='colcon_core.python_testing', -): +def get_python_testing_step_extensions(*, group_name=None): """ Get the available Python testing step extensions. @@ -147,6 +145,8 @@ def get_python_testing_step_extensions( :rtype: OrderedDict """ + if group_name is None: + group_name = 'colcon_core.python_testing' extensions = instantiate_extensions(group_name, unique_instance=False) for name in list(extensions.keys()): extension = extensions[name]