Load a configuration file (JSON or YAML) based on its extension.
(file_path)
| 24 | |
| 25 | |
| 26 | def load_config(file_path): |
| 27 | """Load a configuration file (JSON or YAML) based on its extension.""" |
| 28 | suffix = pathlib.Path(file_path).suffix.lower() |
| 29 | |
| 30 | try: |
| 31 | with open(file_path, 'r', encoding='utf-8') as f: |
| 32 | if suffix in ['.yaml', '.yml'] and YAML_SUPPORT: |
| 33 | return yaml.load(f, Loader=Loader) |
| 34 | else: |
| 35 | return json.load(f) |
| 36 | except Exception as e: |
| 37 | raise RuntimeError(f"Failed to load configuration file '{file_path}': {e}") |
| 38 | |
| 39 | |
| 40 | def validate_config(schema_file, config_file, verbose=False): |