"""YAML config loader and validator.""" from __future__ import annotations from pathlib import Path from typing import Any import yaml REQUIRED = {"distro", "arch"} def load(path: Path) -> dict[str, Any]: """Load and validate a YAML config file.""" with open(path) as f: cfg = yaml.safe_load(f) if not isinstance(cfg, dict): raise ValueError(f"Config must be a YAML mapping, got {type(cfg).__name__}") missing = REQUIRED - cfg.keys() if missing: raise ValueError(f"Missing required fields: {', '.join(sorted(missing))}") # defaults cfg.setdefault("hostname", "euri") cfg.setdefault("users", []) cfg.setdefault("services", []) cfg.setdefault("packages", []) cfg.setdefault("init", "dinit") cfg.setdefault("bootloader", "grub") cfg.setdefault("iso", {}) return cfg