Skip to content

Loader

Env-spec loader.

======================================================================================================================== Name: core/env/loader.py Description: Parses env_data_model.yaml into typed Pydantic models that represent every environment variable defined for the project.

Classes:

Name Description
DBField

Database column specification for ORM code generation.

DBSpec

Database table-level configuration for Peewee models.

DestinationType

Destination module layer for the generated model.

EnvSection

A logical grouping of related environment variables.

EnvSpec

Complete specification container parsed from YAML source files.

EnvVarSpec

Specification for a single environment variable.

SectionType

Categorization for environment configuration sections.

Functions:

Name Description
load_env_spec

Load and parse the environment specification file or directory containing YAML specs.

DBField

Bases: BaseModel

Database column specification for ORM code generation.

DBSpec

Bases: BaseModel

Database table-level configuration for Peewee models.

DestinationType

Bases: StrEnum

Destination module layer for the generated model.

EnvSection

Bases: BaseModel

A logical grouping of related environment variables.

Methods:

Name Description
parse_pyproject_header

Parse comma-separated string headers into a list of strings.

propagate_section_to_variables

Propagate section metadata and environment prefixes down to child variables.

uppercase_prefix

Ensure environmental variable prefix is uppercase.

parse_pyproject_header classmethod

parse_pyproject_header(v: object) -> list[str] | None

Parse comma-separated string headers into a list of strings.

propagate_section_to_variables

propagate_section_to_variables() -> EnvSection

Propagate section metadata and environment prefixes down to child variables.

uppercase_prefix classmethod

uppercase_prefix(v: str) -> str

Ensure environmental variable prefix is uppercase.

EnvSpec

Bases: BaseModel

Complete specification container parsed from YAML source files.

Methods:

Name Description
validate_no_duplicates

Ensure no name collisions exist between env variable keys or Python aliases.

Attributes:

Name Type Description
all_vars list[EnvVarSpec]

A flattened list of all variable specifications across sections.

all_vars property

all_vars: list[EnvVarSpec]

A flattened list of all variable specifications across sections.

validate_no_duplicates

validate_no_duplicates() -> EnvSpec

Ensure no name collisions exist between env variable keys or Python aliases.

EnvVarSpec

Bases: BaseModel

Specification for a single environment variable.

Methods:

Name Description
compute_derived_fields

Derive aliases, environmental names, and secret status post-initialization.

display_value

Return a masked or plain default value suitable for documentation output.

normalize_name

Normalize the variable name to snake_case.

normalize_type

Map generic or YAML type names to standardized Python types.

compute_derived_fields

compute_derived_fields() -> EnvVarSpec

Derive aliases, environmental names, and secret status post-initialization.

display_value

display_value() -> str

Return a masked or plain default value suitable for documentation output.

normalize_name classmethod

normalize_name(v: str) -> str

Normalize the variable name to snake_case.

normalize_type classmethod

normalize_type(v: str) -> str

Map generic or YAML type names to standardized Python types.

SectionType

Bases: StrEnum

Categorization for environment configuration sections.

load_env_spec

load_env_spec(path: str | Path | None = None) -> EnvSpec

Load and parse the environment specification file or directory containing YAML specs.

Parameters:

Name Type Description Default
path str | Path | None

Path to a YAML file or directory containing spec files. Defaults to DEFAULT_SPEC_PATH.

None

Returns:

Name Type Description
EnvSpec EnvSpec

Fully validated specification model populated from YAML content.

Raises:

Type Description
FileNotFoundError

If the designated spec path does not exist.

ValueError

If no section definitions were found.