Spaces:
Sleeping
Sleeping
File size: 1,055 Bytes
07473e9 | 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 32 33 34 35 36 37 | """Load task scenarios from YAML files bundled with the package."""
from __future__ import annotations
import os
from typing import List
import yaml
# Resolve the tasks directory relative to this file so it works regardless of CWD
_TASKS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tasks")
VALID_TASKS = ("easy", "medium", "hard")
def load_scenario(task_name: str) -> dict:
"""Load and return the scenario dict for the given task.
Raises:
ValueError: if task_name is not one of {easy, medium, hard}.
FileNotFoundError: if the YAML file is missing.
"""
if task_name not in VALID_TASKS:
raise ValueError(
f"Unknown task '{task_name}'. Valid tasks: {', '.join(VALID_TASKS)}"
)
path = os.path.join(_TASKS_DIR, f"{task_name}.yaml")
with open(path, "r", encoding="utf-8") as f:
scenario = yaml.safe_load(f)
if "name" not in scenario:
scenario["name"] = task_name
return scenario
def list_tasks() -> List[str]:
return list(VALID_TASKS)
|