Source code for gyoza.deployment.config

"""Gyoza project config loading utilities."""

from __future__ import annotations

from pathlib import Path
from typing import Any

import yaml

_CONFIG_NAMES = ("gyoza.yml", "gyoza.yaml")


[docs] def find_config(project_path: Path) -> Path: """Locate the gyoza config file in a project directory. Parameters ---------- project_path : Path Root directory to search. Returns ------- Path Resolved path to the config file. Raises ------ FileNotFoundError If neither ``gyoza.yml`` nor ``gyoza.yaml`` exists. """ for name in _CONFIG_NAMES: candidate = project_path / name if candidate.exists(): return candidate msg = f"gyoza.yml / gyoza.yaml not found in {project_path}" raise FileNotFoundError(msg)
[docs] def load_config(project_path: Path) -> dict[str, Any]: """Read and parse the gyoza config from a project directory. Parameters ---------- project_path : Path Root directory containing the gyoza config. Returns ------- dict[str, Any] Parsed YAML configuration. Raises ------ FileNotFoundError If the config file is not found. """ config_file = find_config(project_path) with config_file.open() as fh: return yaml.safe_load(fh)