tmt.plugins package

Module contents

Handle Plugins

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.explore_export_package(logger: Logger) None

Import all plugins bundled into tmt.export package

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

Attempt to import requested module

tmt.plugins.import_member(*, module_name: str, member_name: str, logger: Logger) Any

Import member from given module, handle errors nicely