trinity.utils.registry module#
- class trinity.utils.registry.Registry(name: str, default_mapping: dict = {})[源代码]#
基类:
objectA class for registry.
- __init__(name: str, default_mapping: dict = {})[源代码]#
- 参数:
name (str) -- The name of the registry.
default_mapping (dict) -- Default mapping from module names to module paths (strings).
- property name: str#
Get name of current registry.
- 返回:
The name of current registry.
- 返回类型:
str
- property modules: dict#
Get all modules in current registry.
- 返回:
A dict storing modules in current registry.
- 返回类型:
dict
- get(module_key) Any[源代码]#
Get module named module_key from in current registry. If not found, return None.
- 参数:
module_key (str) -- specified module name
- 返回:
the module object
- 返回类型:
Any
- register_module(module_name: str, module_cls: Type = None, force=False, lazy=False)[源代码]#
Register module class object to registry with the specified module name.
- 参数:
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.
示例
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, )