From 7f3bc1df65715a966b6c38e3e7ba0ed2618b5dbc Mon Sep 17 00:00:00 2001 From: Noah Dormann Date: Thu, 11 Apr 2024 01:19:19 +0100 Subject: [PATCH] feat: raise UnsupportedExtensionException when loading .yml files --- hydra/errors.py | 3 +++ hydra/plugins/config_source.py | 9 +++++++-- tests/test_config_loader.py | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/hydra/errors.py b/hydra/errors.py index 8134188770..772c3043b6 100644 --- a/hydra/errors.py +++ b/hydra/errors.py @@ -37,3 +37,6 @@ def __init__( class HydraDeprecationError(HydraException): ... + + +class UnsupportedExtensionException(HydraException): ... diff --git a/hydra/plugins/config_source.py b/hydra/plugins/config_source.py index 182a3ec48a..fe2062a45e 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,7 +116,12 @@ def full_path(self) -> str: @staticmethod def _normalize_file_name(filename: str) -> str: supported_extensions = [".yaml"] - if not version.base_at_least("1.2"): + if version.base_at_least("1.2"): + if filename.endswith(".yml"): + 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( 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,