From 794720ec9a302c6d928a42b30c5f8fa1a7d4d382 Mon Sep 17 00:00:00 2001 From: insolor <2442833+insolor@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:35:57 +0300 Subject: [PATCH] Copypaste config.py code from dfint/search_offsets --- dfint64_patch/config.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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}")