29 lines
747 B
Python
29 lines
747 B
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from .models import SourceConfig
|
|
from .pipeline import _source_config_from_dict
|
|
|
|
|
|
def load_json(path: Path) -> Any:
|
|
return json.loads(path.read_text(encoding="utf-8"))
|
|
|
|
|
|
def load_source_configs(path: Path) -> list[SourceConfig]:
|
|
raw = load_json(path)
|
|
if not isinstance(raw, list):
|
|
raise ValueError("sources config must be a list")
|
|
return [_source_config_from_dict(item) for item in raw]
|
|
|
|
|
|
def load_pipeline_config(path: Path) -> dict[str, Any]:
|
|
if not path.exists():
|
|
return {}
|
|
raw = load_json(path)
|
|
if not isinstance(raw, dict):
|
|
raise ValueError("pipeline config must be an object")
|
|
return raw
|