calypso.utils package

class calypso.utils.LazyLoader(local_name: str, parent_module_globals: Mapping, name: str)

Bases: ModuleType

class calypso.utils.Registry(name)

Bases: Mapping

register_module(module=None, name=None, force=False)

method to register a module

Parameters:
  • module (LazyLoader) – LazyLoader instance of specific module, by default None

  • name (str) – the class name of registry, by default None

  • force (bool, optional) – whether to replace the module in force, by default False

Returns:

module – class of LazyLoader (not instance)

Return type:

LazyLoader

calypso.utils.log_init(level=20, logfile: Path | str | None = None, logdir: Path | str | None = 'log')
calypso.utils.proxy_attrs(hinted_class: Type[C])

A decorator to proxy attributes and methods for class

Parameters:

hinted_class (type) – The class to be proxied. Only hinted attributes and normal methods are proxied, and will be called from _data of the decorated class.

Notes

This decorator is usually used to proxy dataclass.

Examples

>>> class Data:
...     x: str
...     def __init__(self):
...         x = "hinted_x"
...         y = "unhinted_y"
...     def fn(self):
...         return "data"
...     @property
...     def prop(self):
...         return "prop"
...
>>> @proxy_attrs(Data)
... class ProxyData:
...     def __init__(self):
...         self._data = Data()
...
>>> proxyed_data = ProxyData()
>>> proxyed_data.fn()
'data'
>>> proxyed_data.x
'hinted_x'
>>> proxied_data.y  # not hinted attributes
AttributeError: 'ProxyData' object has no attribute 'y'
>>> proxied_data.prop  # not a normal method
AttributeError: 'ProxyData' object has no attribute 'prop'
calypso.utils.seed_everything(seed: int | None = None) int | None
calypso.utils.singleton(cls)

Singleton decorator

Subpackages

Submodules