Skip to content

Commit

Permalink
feat: raise UnsupportedExtensionError when loading .yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
ndormann committed Apr 11, 2024
1 parent 2e682d8 commit 4e87b94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions hydra/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ def __init__(


class HydraDeprecationError(HydraException): ...


class UnsupportedExtensionException(HydraException): ...
9 changes: 7 additions & 2 deletions hydra/plugins/config_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ConfigCompositionException,
HydraException,
MissingConfigException,
UnsupportedExtensionException,
)
from hydra.test_utils.test_utils import chdir_hydra_root
from hydra.types import RunMode
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4e87b94

Please sign in to comment.