tmt.plugins package

Module contents

Handle Plugins

class tmt.plugins.ModuleImporter(module: str, exc_class: type[Exception], exc_message: str)

Bases: Generic[ModuleT]

Import and return a module when called.

A helper class for importing modules that cannot be imported in boot time. Constructs a callable that, when called, would import and return a given module. The module may be already imported, then it’s taken from sys.modules.

class tmt.plugins.PluginRegistry

Bases: Generic[RegisterableT]

A container for plugins of shared purpose.

A fancy wrapper for a dictionary at its core, but allows for nicer annotations and more visible semantics.

get_plugin(plugin_id: str) RegisterableT | None

Find a plugin by its id.

Returns:

plugin or None if no such id has been registered.

items() Iterator[tuple[str, RegisterableT]]
iter_plugin_ids() Iterator[str]
iter_plugins() Iterator[RegisterableT]
register_plugin(*, plugin_id: str, plugin: RegisterableT, raise_on_conflict: bool = True, logger: Logger) None

Register a plugin with this registry.

Parameters:
  • plugin_id – id of the plugin. Works as a label or name, and must may not be used in this registry yet.

  • plugin – a plugin to register.

  • raise_on_conflict

    if set, an exception would be raised when id was already used.

    Note

    As of now, only a warning is logged, no exception is raised. Plugin discovery often happens in import time, and it is hard to manage it correctly without more changes in code.

  • logger – used for logging.

tmt.plugins.discover(path: Path) Iterator[str]

Discover available plugins for given paths

tmt.plugins.explore(logger: Logger, again: bool = False) None

Explore all available plugin locations

By default plugins are explored only once to save time. Repeated call does not have any effect. Use again=True to force plugin exploration even if it has been already completed before.

tmt.plugins.import_member(*, module: str, member: str, logger: Logger) tuple[ModuleT, Any]

Import member from given module, handle errors nicely

tmt.plugins.import_module(*, module: str, path: Path | None = None, logger: Logger) ModuleT

Import a module.

Parameters:
  • module – name of a module to import. It may represent a submodule as well, using common dot notation (foo.bar.baz).

  • path – if specified, it would be incorporated in exception message.

Returns:

imported module.

Raises:

SystemExit – when import fails.