calypso.utils.factory module
- class calypso.utils.factory.Factory(factory_name: str, external_entry_group: str = '', lazy=False)
Bases:
Mapping
[K
,Callable
[[…],V
]],Generic
[K
,V
]Factory to (lazily optional) store modules and attribute like CLS1=app.pkg.module1:cls1.
Roughly like from app.pkg.module1 import cls1 as CLS1.
name: name to register in the factory, refer to CLS1
module_attr_name: name of the module and attribute split by :, refer to app.pkg.module1:cls1
factory_name: name of this factory
external_entry_group: group name for external module
Examples
>>> Array = Factory("myfactory", external_entry_group="") >>> Array.register(module_attr_name="numpy:array", name="nparray") >>> Array["nparray"]([1, 2]) array([1, 2])
- register(module_attr_name, name, force=False)
Register a virtual subclass of an ABC.
Returns the subclass, to allow usage as a class decorator.