Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: raise UnsupportedExtensionException when loading .yml files #2890

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@


class HydraDeprecationError(HydraException): ...


class UnsupportedExtensionException(HydraException): ...
Dismissed Show dismissed Hide dismissed
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 @@
config_loader = ConfigLoaderImpl(
config_search_path=create_config_search_path(path)
)
with raises(UnsupportedExtensionException):
cfg = config_loader.load_configuration(
Dismissed Show dismissed Hide dismissed
config_name="config.yml",
overrides=[],
run_mode=RunMode.RUN,
)
version.setbase("1.1")
with warns(
UserWarning,
Expand Down
Loading