Skip to content

environment_values

environment_values

Classes

NyxEnvironmentConfigValues

Bases: NyxBaseConfigValues

Config values of the environment variables set for the application.

Attributes
source_file = Field(default='') class-attribute instance-attribute

Environment file (NAME=value lines) to load. Nothing is loaded if empty.

vars_overrides = Field(default_factory=dict) class-attribute instance-attribute

Variables set after the source file, so they win over it.

$NAME references in a value are expanded. A removed variable stays set until the application is restarted.

Functions
pre_deserialize(data)

Move variables saved straight under environment to vars_overrides.

Parameters:

Name Type Description Default
data dict[str, Any]

raw values of the section.

required

Returns:

Type Description
dict[str, Any]

values with every key that is not an option of the section taken as a variable.

Source code in src/nyx/core/config_values/environment_values.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def pre_deserialize(self, data: dict[str, typing.Any]) -> dict[str, typing.Any]:
    """Move variables saved straight under `environment` to `vars_overrides`.

    Args:
        data: raw values of the section.

    Returns:
        dict[str, Any]: values with every key that is not an option of the
            section taken as a variable.
    """
    options = {"source_file", "vars_overrides"}
    old_variables = {
        name: value for name, value in data.items() if name not in options
    }
    if not old_variables:
        return data
    migrated = {name: value for name, value in data.items() if name in options}
    migrated["vars_overrides"] = {
        **old_variables,
        **migrated.get("vars_overrides", {}),
    }
    return migrated