The shared module of Hera provides control over global configurations, hooks, and some base mixins.
GlobalConfig
module-attribute
GlobalConfig = _GlobalConfig()
global_config
module-attribute
global_config = _GlobalConfig()
register_pre_build_hook
module-attribute
register_pre_build_hook = global_config.register_pre_build_hook
BaseMixin
Source code in src/hera/shared/_global_config.py
| class BaseMixin(BaseModel):
def _init_private_attributes(self):
"""A pydantic private method called after `__init__`.
Notes:
-----
In order to inject `__hera_init__` after `__init__` without destroying the autocomplete, we opted for
this method. We also tried other ways including creating a metaclass that invokes hera_init after init,
but that always broke auto-complete for IDEs like VSCode.
"""
super()._init_private_attributes()
self.__hera_init__()
def __hera_init__(self):
"""A method that is optionally implemented and invoked by `BaseMixin` subclasses to perform some post init."""
...
@root_validator(pre=True)
def _set_defaults(cls, values):
"""Sets the user-provided defaults of Hera objects."""
defaults = global_config._get_class_defaults(cls)
for key, value in defaults.items():
if values.get(key) is None:
values[key] = value
return values
|