Skip to content

Commit

Permalink
Support alternate group names in get_*_extensions (#647)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cottsay authored May 24, 2024
1 parent a067589 commit db84706
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 27 deletions.
6 changes: 4 additions & 2 deletions colcon_core/argument_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ def decorate_argument_parser(self, *, parser):
raise NotImplementedError()


def get_argument_parser_extensions():
def get_argument_parser_extensions(*, group_name=None):
"""
Get the available argument parser extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
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
return order_extensions_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ def create_environment_hooks(self, prefix_path, pkg_name):
raise NotImplementedError()


def get_environment_extensions():
def get_environment_extensions(*, group_name=None):
"""
Get the available environment extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name in list(extensions.keys()):
extension = extensions[name]
extension.ENVIRONMENT_NAME = name
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/event_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def __call__(self, event):
raise NotImplementedError()


def get_event_handler_extensions(*, context):
def get_event_handler_extensions(*, context, group_name=None):
"""
Get the available event handler extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.EVENT_HANDLER_NAME = name
extension.context = context
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/executor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _flush(self):
self._event_controller.flush()


def get_executor_extensions():
def get_executor_extensions(*, group_name=None):
"""
Get the available executor extensions.
Expand All @@ -206,7 +206,9 @@ def get_executor_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.EXECUTOR_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/package_augmentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ def augment_package(
raise NotImplementedError()


def get_package_augmentation_extensions():
def get_package_augmentation_extensions(*, group_name=None):
"""
Get the available package augmentation extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_AUGMENTATION_NAME = name
return order_extensions_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/package_discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ def discover(self, *, args, identification_extensions):
raise NotImplementedError()


def get_package_discovery_extensions():
def get_package_discovery_extensions(*, group_name=None):
"""
Get the available package discovery extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_DISCOVERY_NAME = name
return order_extensions_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/package_identification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def identify(self, desc: PackageDescriptor):
raise NotImplementedError()


def get_package_identification_extensions():
def get_package_identification_extensions(*, group_name=None):
"""
Get the available package identification extensions.
Expand All @@ -73,7 +73,9 @@ def get_package_identification_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_IDENTIFICATION_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/package_selection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ def add_arguments(parser):
_add_package_selection_arguments(parser)


def get_package_selection_extensions():
def get_package_selection_extensions(*, group_name=None):
"""
Get the available package selection extensions.
The extensions are ordered by their entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PACKAGE_SELECTION_NAME = name
return order_extensions_by_priority(extensions)
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/prefix_path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def extend_prefix_path(self, paths):
raise NotImplementedError()


def get_prefix_path_extensions():
def get_prefix_path_extensions(*, group_name=None):
"""
Get the available prefix path extensions.
Expand All @@ -49,7 +49,9 @@ def get_prefix_path_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.PREFIX_PATH_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down
13 changes: 9 additions & 4 deletions colcon_core/shell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ async def generate_command_environment(
raise NotImplementedError()


def get_shell_extensions():
def get_shell_extensions(*, group_name=None):
"""
Get the available shell extensions.
Expand All @@ -282,7 +282,9 @@ def get_shell_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.SHELL_NAME = name
return order_extensions_grouped_by_priority(extensions)
Expand Down Expand Up @@ -593,7 +595,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=None):
"""
Get the available package identification extensions.
Expand All @@ -602,7 +604,10 @@ def get_find_installed_packages_extensions():
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__ + '.find_installed_packages')
if group_name is None:
group_name = __name__
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)
Expand Down
7 changes: 4 additions & 3 deletions colcon_core/task/python/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,17 @@ async def step(self):
raise NotImplementedError()


def get_python_testing_step_extensions():
def get_python_testing_step_extensions(*, group_name=None):
"""
Get the available Python testing step extensions.
The extensions are ordered by their priority and entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(
'colcon_core.python_testing', unique_instance=False)
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]
extension.STEP_TYPE = name
Expand Down
6 changes: 4 additions & 2 deletions colcon_core/verb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ def main(self, *, context):
raise NotImplementedError()


def get_verb_extensions():
def get_verb_extensions(*, group_name=None):
"""
Get the available verb extensions.
The extensions are ordered by their entry point name.
:rtype: OrderedDict
"""
extensions = instantiate_extensions(__name__)
if group_name is None:
group_name = __name__
extensions = instantiate_extensions(group_name)
for name, extension in extensions.items():
extension.VERB_NAME = name
return order_extensions_by_name(extensions)
Expand Down

0 comments on commit db84706

Please sign in to comment.