diff --git a/dfint64_patch/config.py b/dfint64_patch/config.py index dd25c2f..94173f2 100644 --- a/dfint64_patch/config.py +++ b/dfint64_patch/config.py @@ -1,30 +1,28 @@ import functools from collections.abc import Callable -from typing import TypeVar from loguru import logger from omegaconf import DictConfig, OmegaConf -T = TypeVar("T", bound=DictConfig) - -def with_config(config_class: type[T], config_file: str) -> Callable[[Callable[[T], None]], Callable[[], None]]: +def with_config(config_class: type, *config_files: str) -> Callable[[Callable[[DictConfig], None]], Callable[[], None]]: """ A decorator to load the config file and merge it with the CLI options. """ - def decorator(func: Callable[[T], None]) -> Callable[[], None]: + def decorator(func: Callable[[DictConfig], None]) -> Callable[[], None]: @functools.wraps(func) def wrapper() -> None: config = OmegaConf.structured(config_class) - try: - config.merge_with(OmegaConf.load(config_file)) - except FileNotFoundError: - logger.info(f"Config {config_file} not found, using CLI options only") - config.merge_with(OmegaConf.from_cli()) + for config_file in config_files: + try: + config.merge_with(OmegaConf.load(config_file)) + except FileNotFoundError: # noqa: PERF203 + logger.info(f"Config {config_file} not found, using CLI options only") + missing = ", ".join(OmegaConf.missing_keys(config)) if missing: logger.error(f"Missing configuration keys: {missing}")