clabe.settings ¶
Settings: ServiceSettings (read from the environment, clabe.yml files and an in-memory document), the
clabe.yml files the launcher knows, and where it keeps temporary files.
Service ¶
Bases: ABC
Abstract base class for all services in the application.
This may be needed in the future to ensure a common interface.
ServiceSettings ¶
Bases: BaseSettings, ABC
Base class for service settings with YAML configuration support.
This class provides automatic YAML configuration loading using pydantic-settings. Highest priority first: keyword
arguments, the in-memory document (--clabe-yml, set_clabe_yml or override_clabe_yml),
./local/clabe.yml, %PROGRAMDATA%/clabe.yml, then environment variables named
CLABE_<SECTION>_<FIELD> (e.g. CLABE_WATCHDOG_JOB_TYPE; CLABE_<FIELD> without a section).
Attributes:
| Name | Type | Description |
|---|---|---|
__yml_section__ |
str | None
|
Optional class variable to override the config section name |
Example
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |
Source code in src/clabe/settings.py
EnvSettings ¶
Bases: ServiceSettings
Settings read only from keyword arguments and environment variables (<__env_prefix__><FIELD>), never
from clabe.yml: the daemon's (DAEMON_CLABE_) and the hub's (no prefix: they live in its container's .env).
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Keyword arguments, then the environment, then a .env file when the class names one.
Source code in src/clabe/settings.py
set_clabe_yml ¶
Installs a process-wide, in-memory configuration document.
The document has the same shape as a clabe.yml file (top-level keys are __yml_section__ names) and is
consulted by every ServiceSettings subclass constructed afterwards. It takes priority over all
known config files except ./local/clabe.yml. Settings objects created before this call are not affected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Mapping[str, Any] | None
|
The configuration document, e.g. fetched from a database. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Example
Source code in src/clabe/settings.py
override_clabe_yml ¶
Temporarily overrides the in-memory configuration document for the current context.
While active, the given document replaces the one installed by set_clabe_yml. Passing None
disables the in-memory document inside the block. The override is scoped with a ContextVar, so it
does not leak across threads or asyncio tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Mapping[str, Any] | None
|
The configuration document to use inside the block. |
required |
Source code in src/clabe/settings.py
get_clabe_yml ¶
Returns the active in-memory configuration document, if any.
A document set via override_clabe_yml takes precedence over the one set via set_clabe_yml.
Returns:
| Type | Description |
|---|---|
Mapping[str, Any] | None
|
The active configuration document, or |
Source code in src/clabe/settings.py
split_list ¶
A list from an environment variable: a JSON list, or items separated by ;; anything else unchanged.