"""What the cycle needs to know of a project's definitions, all from dbt's manifest: its period types and its cohorts.""" import json from pathlib import Path from models.io.storage import cohort_urls as _cohort_urls def period_types(proyecto: str, manifest: Path) -> list[str]: """The period types the project's measures publish, from their `meta.tipos_periodo` in dbt's manifest.""" metrics = json.loads(manifest.read_text(encoding="utf-8"))["metrics"].values() return sorted({t for m in metrics for t in m["config"].get("meta", {}).get("tipos_periodo", []) if m["config"]["meta"].get("measure_url", "").startswith(f"{proyecto}/")}) def cohort_urls(proyecto: str, manifest: Path | None) -> list[str]: """The cohorts the cycle builds: those of the project in dbt's manifest (`Transformation/models//cohorts/`, `meta.cohort` of their population query). dbt is their only definition. None without a manifest.""" return _cohort_urls(manifest, proyecto) if manifest else []