| """Configuration loader with validation.""" | |
| import json | |
| from pathlib import Path | |
| from .config_models import EvaluationConfig | |
| def load_config(config_path: str | Path) -> EvaluationConfig: | |
| """Load and validate configuration from JSON file. | |
| Args: | |
| config_path: Path to configuration JSON file | |
| Returns: | |
| Validated EvaluationConfig instance | |
| Raises: | |
| FileNotFoundError: If config file doesn't exist | |
| ValueError: If configuration is invalid | |
| """ | |
| path = Path(config_path) | |
| if not path.exists(): | |
| raise FileNotFoundError( | |
| f"Configuration file not found: {config_path}\n" | |
| f"Please create config file at: {path.absolute()}" | |
| ) | |
| try: | |
| with open(path, "r") as f: | |
| config_dict = json.load(f) | |
| except json.JSONDecodeError as e: | |
| raise ValueError(f"Invalid JSON in config file {config_path}: {e}") from e | |
| try: | |
| config = EvaluationConfig(**config_dict) | |
| except Exception as e: | |
| raise ValueError(f"Configuration validation failed: {e}") from e | |
| return config | |