exlab_wizard.config.loader#

config.yaml round-trip loader. Backend Spec §9.

Uses ruamel.yaml in round-trip mode so saving back to disk preserves operator-readable comments and key order. The Settings UI’s Save action goes through this module so config.yaml stays human-friendly across edit cycles.

Functions

apply_test_mode_prefix(config)

Return config with each equipment id prefixed by TEST_MODE_PREFIX.

dump_config(config)

Serialize config to a YAML string.

load_config(path)

Load a config.yaml from disk and validate against the Pydantic model.

load_config_from_text(text)

Load a config from YAML text.

save_config(path, config, *[, original_text])

Atomically write config back to path.

exlab_wizard.config.loader.apply_test_mode_prefix(config)[source]#

Return config with each equipment id prefixed by TEST_MODE_PREFIX.

Idempotent: an id that already begins with the prefix is left unchanged so repeated applications (or already-prefixed inputs) never grow a TEST_TEST_… chain. The rewritten config is re-run through Config.model_validate() so unique-id and pattern invariants are re-checked against the new ids – if a rewrite ever produces a duplicate or an over-length id, the loader raises the same ConfigError shape a hand-edited config would.

Parameters:

config (Config)

Return type:

Config

exlab_wizard.config.loader.dump_config(config)[source]#

Serialize config to a YAML string. No comment preservation; tests use this.

Parameters:

config (Config)

Return type:

str

exlab_wizard.config.loader.load_config(path)[source]#

Load a config.yaml from disk and validate against the Pydantic model.

Raises ConfigError on filesystem error, YAML parse error, or model validation failure. The original ValidationError is chained as the cause so the caller can introspect per-field errors.

Parameters:

path (Path)

Return type:

Config

exlab_wizard.config.loader.load_config_from_text(text)[source]#

Load a config from YAML text. Same semantics as load_config but for in-memory input.

Parameters:

text (str)

Return type:

Config

exlab_wizard.config.loader.save_config(path, config, *, original_text=None)[source]#

Atomically write config back to path.

If original_text is supplied, ruamel.yaml round-trips it so existing comments and key order are preserved; only the modified values change. If original_text is None, write a fresh document with no preserved formatting.

Atomicity: write to <path>.tmp, fsync, then Path.replace to <path>.

Parameters:
Return type:

None