trinity.utils.registry module

class trinity.utils.registry.Registry(name: str)[source]

Bases: object

A class for registry.

__init__(name: str)[source]
Parameters:

name (str) – The name of the registry.

property name: str

Get name of current registry.

Returns:

The name of current registry.

Return type:

str

property modules: dict

Get all modules in current registry.

Returns:

A dict storing modules in current registry.

Return type:

dict

list() None[source]

Logging the list of module in current registry.

get(module_key) Any[source]

Get module named module_key from in current registry. If not found, return None.

Parameters:

module_key (str) – specified module name

Returns:

the module object

Return type:

Any

register_module(module_name: str, module_cls: Type | None = None, force=False, lazy=False)[source]

Register module class object to registry with the specified module name.

Parameters:
  • module_name (str) – The module name.

  • module_cls (Type) – module class object

  • force (bool) – Whether to override an existing class with the same name. Default: False.

  • lazy (bool) – Whether to register the module class object lazily. Default: False.

Example

WORKFLOWS = Registry("workflows")

# register a module using decorator
@WORKFLOWS.register_module(name="workflow_name")
class MyWorkflow(Workflow):
    pass

# or register a module directly
WORKFLOWS.register_module(
    name="workflow_name",
    module_cls=MyWorkflow,
    force=True,
)