File size: 930 Bytes
43b2c38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
# ui/intake/loader.py
from __future__ import annotations

from functools import lru_cache
from pathlib import Path
from typing import Any

import yaml

DATA_DIR = Path(__file__).resolve().parents[2] / "data" / "intake"
CHOICES_DIR = DATA_DIR / "choices"


@lru_cache(maxsize=1)
def load_intake_choices() -> dict[str, list[str]]:
    choices: dict[str, list[str]] = {}
    for path in sorted(CHOICES_DIR.glob("*.yaml")):
        with path.open(encoding="utf-8") as handle:
            data = yaml.safe_load(handle)
        if not isinstance(data, list):
            raise ValueError(f"{path.name} must contain a YAML list")
        choices[path.stem] = list(data)
    return choices


@lru_cache(maxsize=1)
def load_demo_personas() -> list[dict[str, Any]]:
    with (DATA_DIR / "personas.yaml").open(encoding="utf-8") as handle:
        data = yaml.safe_load(handle)
    return list(data["personas"])