def instantiate_extensions(group_name, *, exclude_names=None, unique_instance=False): """ Instantiate all extensions within a group. :param str group_name: the name of the `entry_point` group :param exclude_names: a list of entry point names to exclude :param bool unique_instance: The flag if each extensions should be instantiated even when it has been created and cached before :returns: dict of extensions """ extension_types = load_entry_points(group_name, exclude_names=exclude_names) extension_instances = {} for extension_name, extension_class in extension_types.items(): extension_instance = _instantiate_extension( group_name, extension_name, extension_class, unique_instance=unique_instance) if extension_instance is None: continue extension_instances[extension_name] = extension_instance return extension_instances
def test_load_entry_points_with_exception(_): with patch('colcon_core.entry_point.logger.error') as error: extensions = load_entry_points('group') # the entry point raising an exception different than a runtime error # results in an error message assert error.call_count == 1 assert len(error.call_args[0]) == 1 assert "Exception loading extension 'group.exception'" \ in error.call_args[0][0] assert 'entry point raising exception' in error.call_args[0][0] # neither of the entry points was loaded successfully assert extensions == {'success': None}
def get_environment_variables_epilog(group_name): """ Get a message enumerating the registered environment variables. :param str group_name: The entry point group name for the environment variable extensions :returns: The message for the argument parser epilog :rtype: str """ # list environment variables with descriptions entry_points = load_entry_points(group_name) env_vars = { env_var.name: env_var.description for env_var in entry_points.values()} epilog_lines = [] for name in sorted(env_vars.keys()): epilog_lines += _format_pair(name, env_vars[name], indent=2, align=24) return 'Environment variables:\n' + '\n'.join(epilog_lines)
def get_python_testing_step_extension(step_name): """ Get a specific Python testing step extension. :param str step_name: The entry point name of the extension :returns: A unique instance of the extension, otherwise None """ group_name = 'colcon_core.python_testing' extension_types = load_entry_points(group_name) extension_names = list(extension_types.keys()) if step_name not in extension_names: return None extension_names.remove(step_name) extensions = instantiate_extensions( group_name, exclude_names=extension_names, unique_instance=True) if step_name not in extensions: return None extension = extensions[step_name] extension.STEP_NAME = step_name return extension