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 1af7b56
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions hydra/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ def __init__(


class HydraDeprecationError(HydraException): ...

class UnsupportedExtensionException(HydraException): ...
13 changes: 9 additions & 4 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,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):
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 1af7b56

Please sign in to comment.