File size: 792 Bytes
275b5a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from __future__ import annotations

from pathlib import Path
from typing import Any

import yaml


SECTIONS = ("data", "model", "diffusion", "training", "output")


def load_config(path: Path) -> dict[str, Any]:
    with path.open("r", encoding="utf-8") as handle:
        config = yaml.safe_load(handle)
    if not isinstance(config, dict):
        raise ValueError(f"Config must contain a mapping: {path}")
    missing = [section for section in SECTIONS if not isinstance(config.get(section), dict)]
    if missing:
        raise ValueError(f"Missing config sections: {', '.join(missing)}")
    return config


def resolve_path(project_root: Path, value: str) -> Path:
    path = Path(value).expanduser()
    return path.resolve() if path.is_absolute() else (project_root / path).resolve()