ConfZ¶
- class confz.ConfZ¶
Bases:
pydantic.main.BaseModel
Base class, parent of every config class. Internally wraps
BaseModel
of pydantic and behaves transparent except for two cases:If the constructor gets config_sources as kwarg, these sources are used as input to enrich the other kwargs.
If the class has the class variable CONFIG_SOURCES defined, these sources are used as input.
In the latter case, a singleton mechanism is activated, returning the same config class instance every time the constructor is called.
- CONFIG_SOURCES: ClassVar[ConfZSources] = None¶
Sources to use as input.
- classmethod change_config_sources(config_sources: confz.confz_source.ConfZSources) contextlib.AbstractContextManager ¶
Change the CONFIG_SOURCES class variable within a controlled context. Within this context, the sources will be different and the singleton reset. This can be useful in unit tests to temporarily change a configuration.
- Parameters
config_sources – The temporary config sources for within the context.
- Returns
Context manager for change of config sources.
- confz.depends_on(*args)¶
Decorator to transform a function into a singleton and register it to a set of config classes.
- confz.validate_all_configs(include_listeners: bool = False)¶
Instantiates all config classes with a singleton mechanism (CONFIG_SOURCES set). This allows to catch validation errors early instead of waiting for the first access.
- Parameters
include_listeners – Whether all listeners (marked with
depends_on()
) should be included.- Raises
ConfZException – If any config could not be loaded.