Skip to content

Plugin

The plugin module contains the interface definitions and utility functions used to load generator plugins used in the TIM context templating configuration.

Generator

Interface definition of generator plugin.

Generator plugins can be added through the entry points system. A generator must have a name and a create method accepting a seed store. The create method must create some sort of random data generator object initialized with a seed/s from the given seed store. This object will then be available in TIM context templates Jinja2 logic.

name: str property readonly

The name under which the random data generator object will be accessible.

create(self, seed_store)

The main function used to create random data generator objects.

Parameters:

Name Type Description Default
seed_store SeedStore

The seed store to be used for random seed generation.

required

Returns:

Type Description
Any

A random data generator object or function.

Source code in generator/plugin.py
def create(self, seed_store: SeedStore) -> Any:
    """The main function used to create random data generator objects.

    Args:
        seed_store: The seed store to be used for random seed generation.

    Returns:
        A random data generator object or function.
    """
    ...

get_generators(plugin_config)

Utility function for getting a list of all available generator plugins.

Parameters:

Name Type Description Default
plugin_config PluginConfig

The plugin configuration policy

required

Returns:

Type Description
List[cr_kyoushi.generator.plugin.Generator]

List of the loaded generator plugins.

Source code in generator/plugin.py
def get_generators(plugin_config: PluginConfig) -> List[Generator]:
    """Utility function for getting a list of all available generator plugins.

    Args:
        plugin_config: The plugin configuration policy

    Returns:
        List of the loaded generator plugins.
    """
    return [
        ep.load()()  # type: ignore[attr-defined]
        for ep in entry_points(group=GENERATOR_ENTRYPOINT)  # type: ignore[call-arg]
        if _check_plugin_allowed(ep, plugin_config)  # type: ignore[arg-type]
    ]