From c402d0c79bfdaee463dc0fb595539633693038a4 Mon Sep 17 00:00:00 2001 From: Andre Perkins Date: Wed, 11 Feb 2026 16:23:51 -0800 Subject: [PATCH 1/2] Add validation entrypoint --- fme/downscaling/validate_config.py | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 fme/downscaling/validate_config.py diff --git a/fme/downscaling/validate_config.py b/fme/downscaling/validate_config.py new file mode 100644 index 000000000..321c8ca27 --- /dev/null +++ b/fme/downscaling/validate_config.py @@ -0,0 +1,63 @@ +import argparse +from typing import TypeVar + +import dacite +import yaml + +from .evaluator import EvaluatorConfig +from .inference import InferenceConfig +from .predict import DownscalerConfig +from .train import TrainerConfig + +T = TypeVar("T") + +CONFIG_CHOICES = ["train", "inference", "evaluator", "predict"] + +CONFIG_CLASSES: dict[str, type] = { + "train": TrainerConfig, + "inference": InferenceConfig, + "evaluator": EvaluatorConfig, + "predict": DownscalerConfig, +} + + +def validate_config(config_dict: dict, data_class: type[T]) -> T: + return dacite.from_dict( + data_class=data_class, + data=config_dict, + config=dacite.Config(strict=True), + ) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Validate a downscaling entrypoint config from a YAML file." + ) + parser.add_argument( + "config_type", + type=str, + help=( + "Kind of configuration to validate. " f"Expected one of: {CONFIG_CHOICES}." + ), + ) + parser.add_argument( + "config_file", + type=str, + help="Path to the configuration file (YAML).", + ) + args = parser.parse_args() + + if args.config_type not in CONFIG_CLASSES: + raise ValueError( + f"Unrecognized config type: '{args.config_type}'. " + f"Expected one of: {CONFIG_CHOICES}." + ) + + with open(args.config_file) as f: + config_dict = yaml.safe_load(f) + + try: + validate_config(config_dict, CONFIG_CLASSES[args.config_type]) + print("Configuration is valid.") + except dacite.DaciteError as e: + print(f"Configuration validation failed: {e}") From 9344a08494707d69320def097be6c54e7f3dc0b1 Mon Sep 17 00:00:00 2001 From: Andre Perkins Date: Wed, 11 Feb 2026 16:26:54 -0800 Subject: [PATCH 2/2] Don't catch validation error --- fme/downscaling/validate_config.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fme/downscaling/validate_config.py b/fme/downscaling/validate_config.py index 321c8ca27..6b4268feb 100644 --- a/fme/downscaling/validate_config.py +++ b/fme/downscaling/validate_config.py @@ -55,9 +55,5 @@ def validate_config(config_dict: dict, data_class: type[T]) -> T: with open(args.config_file) as f: config_dict = yaml.safe_load(f) - - try: validate_config(config_dict, CONFIG_CLASSES[args.config_type]) print("Configuration is valid.") - except dacite.DaciteError as e: - print(f"Configuration validation failed: {e}")