From 1af7b5622570da37bb9361638ae9b9f5edacf851 Mon Sep 17 00:00:00 2001 From: Noah Dormann Date: Thu, 11 Apr 2024 01:19:19 +0100 Subject: [PATCH] feat: raise UnsupportedExtensionError when loading .yml files --- hydra/errors.py | 2 ++ hydra/plugins/config_source.py | 13 +++++++++---- tests/test_config_loader.py | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hydra/errors.py b/hydra/errors.py index 8134188770..16af432a46 100644 --- a/hydra/errors.py +++ b/hydra/errors.py @@ -37,3 +37,5 @@ def __init__( class HydraDeprecationError(HydraException): ... + +class UnsupportedExtensionException(HydraException): ... diff --git a/hydra/plugins/config_source.py b/hydra/plugins/config_source.py index 182a3ec48a..f26149f305 100644 --- a/hydra/plugins/config_source.py +++ b/hydra/plugins/config_source.py @@ -10,7 +10,7 @@ from hydra._internal.deprecation_warning import deprecation_warning from hydra.core.default_element import InputDefault from hydra.core.object_type import ObjectType -from hydra.errors import HydraException +from hydra.errors import HydraException, UnsupportedExtensionException from hydra.plugins.plugin import Plugin @@ -116,10 +116,15 @@ def full_path(self) -> str: @staticmethod def _normalize_file_name(filename: str) -> str: supported_extensions = [".yaml"] - if not version.base_at_least("1.2"): - supported_extensions.append(".yml") + if version.base_at_least("1.2"): if filename.endswith(".yml"): - deprecation_warning( + raise UnsupportedExtensionException( + ".yml files are not supported. Use .yaml extension for Hydra config files." + ) + else: + supported_extensions.append(".yml") + if filename.endswith(".yml"): + deprecation_warning( "Support for .yml files is deprecated. Use .yaml extension for Hydra config files" ) if not any(filename.endswith(ext) for ext in supported_extensions): diff --git a/tests/test_config_loader.py b/tests/test_config_loader.py index ebf0088a19..ac128532cc 100644 --- a/tests/test_config_loader.py +++ b/tests/test_config_loader.py @@ -17,6 +17,7 @@ ConfigCompositionException, HydraException, MissingConfigException, + UnsupportedExtensionException, ) from hydra.test_utils.test_utils import chdir_hydra_root from hydra.types import RunMode @@ -190,6 +191,12 @@ def test_load_yml_file(self, path: str, hydra_restore_singletons: Any) -> None: config_loader = ConfigLoaderImpl( config_search_path=create_config_search_path(path) ) + with raises(UnsupportedExtensionException): + cfg = config_loader.load_configuration( + config_name="config.yml", + overrides=[], + run_mode=RunMode.RUN, + ) version.setbase("1.1") with warns( UserWarning,