Skip to content

plugins

trestle.core.plugins ¤

Plugin discovery code.

Attributes¤

logger = logging.getLogger(__name__) module-attribute ¤

Functions¤

discovered_plugins(search_module) ¤

Yield discovered plugin classes within a given module name.

Source code in trestle/core/plugins.py
36
37
38
39
40
41
42
43
44
45
46
47
def discovered_plugins(search_module: str) -> Iterator[Tuple[str, Any]]:
    """Yield discovered plugin classes within a given module name."""
    logger.debug(_discovered_plugins)
    # This block is uncovered as trestle cannot find plugins in it's unit tests - it is the base module.
    for plugin, value in _discovered_plugins.items():  # pragma: nocover
        for _, module, _ in pkgutil.iter_modules([pathlib.Path(value.__path__[0], search_module)]):
            logger.debug(module)
            plugin_module = importlib.import_module(f'{plugin}.{search_module}.{module}')
            clsmembers = inspect.getmembers(plugin_module, inspect.isclass)
            logger.debug(clsmembers)
            for _, plugin_cls in clsmembers:
                yield (plugin, plugin_cls)

handler: python