Files
claudini/claudini/configs.py
T
Peter Romov 5b6058b3c4 Initial commit
Co-Authored-By: Alexander Panfilov <sasha_pusha@mail.de>
Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-25 02:09:26 +00:00

43 lines
1.2 KiB
Python

"""
Named config presets for Claudini experiments.
Presets are loaded from YAML files in configs/*.yaml (project root).
Each preset's filename (without .yaml) becomes its name, used as the
first positional argument on the CLI and as the track name for results.
"""
from pathlib import Path
import yaml
_PRESETS_DIR = Path(__file__).resolve().parents[1] / "configs"
def _load_presets() -> dict:
presets = {}
for path in sorted(_PRESETS_DIR.glob("*.yaml")):
with open(path) as f:
presets[path.stem] = yaml.safe_load(f)
return presets
PRESETS = _load_presets()
def resolve_preset(preset: str) -> tuple[dict, str]:
"""Return (preset_cfg, track) for a named preset or a path to a YAML file.
Raises ValueError if the preset name is unknown and the path does not exist.
"""
if preset in PRESETS:
return PRESETS[preset], preset
preset_path = Path(preset)
if not preset_path.exists():
raise ValueError(
f"Unknown preset '{preset}'. Available: {', '.join(PRESETS.keys())}. "
"Alternatively, supply a path to a YAML preset file."
)
with preset_path.open() as f:
return yaml.safe_load(f), preset_path.stem