Skip to content

Commit 7f3bc1d

Browse files
committed
feat: raise UnsupportedExtensionException when loading .yml files
1 parent 2e682d8 commit 7f3bc1d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

hydra/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ def __init__(
3737

3838

3939
class HydraDeprecationError(HydraException): ...
40+
41+
42+
class UnsupportedExtensionException(HydraException): ...

hydra/plugins/config_source.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from hydra._internal.deprecation_warning import deprecation_warning
1111
from hydra.core.default_element import InputDefault
1212
from hydra.core.object_type import ObjectType
13-
from hydra.errors import HydraException
13+
from hydra.errors import HydraException, UnsupportedExtensionException
1414
from hydra.plugins.plugin import Plugin
1515

1616

@@ -116,7 +116,12 @@ def full_path(self) -> str:
116116
@staticmethod
117117
def _normalize_file_name(filename: str) -> str:
118118
supported_extensions = [".yaml"]
119-
if not version.base_at_least("1.2"):
119+
if version.base_at_least("1.2"):
120+
if filename.endswith(".yml"):
121+
raise UnsupportedExtensionException(
122+
".yml files are not supported. Use .yaml extension for Hydra config files."
123+
)
124+
else:
120125
supported_extensions.append(".yml")
121126
if filename.endswith(".yml"):
122127
deprecation_warning(

tests/test_config_loader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ConfigCompositionException,
1818
HydraException,
1919
MissingConfigException,
20+
UnsupportedExtensionException,
2021
)
2122
from hydra.test_utils.test_utils import chdir_hydra_root
2223
from hydra.types import RunMode
@@ -190,6 +191,12 @@ def test_load_yml_file(self, path: str, hydra_restore_singletons: Any) -> None:
190191
config_loader = ConfigLoaderImpl(
191192
config_search_path=create_config_search_path(path)
192193
)
194+
with raises(UnsupportedExtensionException):
195+
cfg = config_loader.load_configuration(
196+
config_name="config.yml",
197+
overrides=[],
198+
run_mode=RunMode.RUN,
199+
)
193200
version.setbase("1.1")
194201
with warns(
195202
UserWarning,

0 commit comments

Comments
 (0)