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

Clean-up of the deprecated strict flag #1396

Merged
merged 2 commits into from
Feb 13, 2021
Merged
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
11 changes: 1 addition & 10 deletions hydra/_internal/config_loader_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ class ConfigLoaderImpl(ConfigLoader):
def __init__(
self,
config_search_path: ConfigSearchPath,
default_strict: Optional[bool] = True,
) -> None:
self.default_strict = default_strict
self.config_search_path = config_search_path
self.repository = ConfigRepository(config_search_path=config_search_path)

Expand Down Expand Up @@ -144,15 +142,13 @@ def load_configuration(
config_name: Optional[str],
overrides: List[str],
run_mode: RunMode,
strict: Optional[bool] = None,
from_shell: bool = True,
) -> DictConfig:
try:
return self._load_configuration_impl(
config_name=config_name,
overrides=overrides,
run_mode=run_mode,
strict=strict,
from_shell=from_shell,
)
except OmegaConfBaseException as e:
Expand All @@ -163,15 +159,11 @@ def _load_configuration_impl(
config_name: Optional[str],
overrides: List[str],
run_mode: RunMode,
strict: Optional[bool] = None,
from_shell: bool = True,
) -> DictConfig:
self.ensure_main_config_source_available()
caching_repo = CachingConfigRepository(self.repository)

if strict is None:
strict = self.default_strict

parser = OverridesParser.create()
parsed_overrides = parser.parse_overrides(overrides=overrides)

Expand All @@ -193,7 +185,7 @@ def _load_configuration_impl(
defaults=defaults_list.defaults, repo=caching_repo
)

OmegaConf.set_struct(cfg, strict)
OmegaConf.set_struct(cfg, True)
OmegaConf.set_readonly(cfg.hydra, False)

# Apply command line overrides after enabling strict flag
Expand Down Expand Up @@ -240,7 +232,6 @@ def load_sweep_config(
overrides = overrides + sweep_overrides
sweep_config = self.load_configuration(
config_name=master_config.hydra.job.config_name,
strict=self.default_strict,
overrides=overrides,
run_mode=RunMode.RUN,
)
Expand Down
24 changes: 2 additions & 22 deletions hydra/_internal/hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import string
import sys
import warnings
from argparse import ArgumentParser
from collections import defaultdict
from typing import Any, Callable, DefaultDict, List, Optional, Sequence, Type, Union
Expand Down Expand Up @@ -44,34 +43,21 @@ def create_main_hydra_file_or_module(
calling_module: Optional[str],
config_path: Optional[str],
job_name: str,
strict: Optional[bool],
) -> "Hydra":
config_search_path = create_automatic_config_search_path(
calling_file, calling_module, config_path
)

return Hydra.create_main_hydra2(job_name, config_search_path, strict)
return Hydra.create_main_hydra2(job_name, config_search_path)

@classmethod
def create_main_hydra2(
cls,
task_name: str,
config_search_path: ConfigSearchPath,
strict: Optional[bool],
) -> "Hydra":

if strict is None:
strict = True
else:
# DEPRECATED: remove in 1.1
msg = (
"\[email protected](strict) flag is deprecated and will removed in the next version."
"\nSee https://hydra.cc/docs/next/upgrades/0.11_to_1.0/strict_mode_flag_deprecated"
)
warnings.warn(message=msg, category=UserWarning)

config_loader: ConfigLoader = ConfigLoaderImpl(
config_search_path=config_search_path, default_strict=strict
config_search_path=config_search_path
)

hydra = cls(task_name=task_name, config_loader=config_loader)
Expand Down Expand Up @@ -119,11 +105,9 @@ def multirun(
overrides: List[str],
with_log_configuration: bool = True,
) -> Any:
# Initial config is loaded without strict (individual job configs may have strict).
cfg = self.compose_config(
config_name=config_name,
overrides=overrides,
strict=False,
with_log_configuration=with_log_configuration,
run_mode=RunMode.MULTIRUN,
)
Expand Down Expand Up @@ -521,7 +505,6 @@ def compose_config(
config_name: Optional[str],
overrides: List[str],
run_mode: RunMode,
strict: Optional[bool] = None,
with_log_configuration: bool = False,
from_shell: bool = True,
) -> DictConfig:
Expand All @@ -530,16 +513,13 @@ def compose_config(
:param overrides:
:param run_mode: compose config for run or for multirun?
:param with_log_configuration: True to configure logging subsystem from the loaded config
:param strict: None for default behavior (default to true for config file, false if no config file).
otherwise forces specific behavior.
:param from_shell: True if the parameters are passed from the shell. used for more helpful error messages
:return:
"""

cfg = self.config_loader.load_configuration(
config_name=config_name,
overrides=overrides,
strict=strict,
run_mode=run_mode,
from_shell=from_shell,
)
Expand Down
3 changes: 1 addition & 2 deletions hydra/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def _run_hydra(
task_function: TaskFunction,
config_path: Optional[str],
config_name: Optional[str],
strict: Optional[bool],
) -> None:

from hydra.core.global_hydra import GlobalHydra
Expand Down Expand Up @@ -332,7 +331,7 @@ def add_conf_dir() -> None:
run_and_report(add_conf_dir)
hydra = run_and_report(
lambda: Hydra.create_main_hydra2(
task_name=task_name, config_search_path=search_path, strict=strict
task_name=task_name, config_search_path=search_path
)
)

Expand Down
1 change: 0 additions & 1 deletion hydra/core/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def load_configuration(
config_name: Optional[str],
overrides: List[str],
run_mode: RunMode,
strict: Optional[bool] = None,
from_shell: bool = True,
) -> DictConfig:
...
Expand Down
3 changes: 0 additions & 3 deletions hydra/experimental/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
def compose(
config_name: Optional[str] = None,
overrides: List[str] = [],
strict: Optional[bool] = None,
return_hydra_config: bool = False,
) -> DictConfig:
"""
:param config_name: the name of the config
(usually the file name without the .yaml extension)
:param overrides: list of overrides for config file
:param strict: optionally override the default strict mode
:param return_hydra_config: True to return the hydra config node in the result
:return: the composed config
"""
Expand All @@ -32,7 +30,6 @@ def compose(
config_name=config_name,
overrides=overrides,
run_mode=RunMode.RUN,
strict=strict,
from_shell=False,
with_log_configuration=False,
)
Expand Down
8 changes: 1 addition & 7 deletions hydra/experimental/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ class initialize:
- Jupyter notebooks.
:param config_path: path relative to the parent of the caller
:param job_name: the value for hydra.job.name (By default it is automatically detected based on the caller)
:param strict: (Deprecated), will be removed in the next major version
:param caller_stack_depth: stack depth of the caller, defaults to 1 (direct caller).
"""

def __init__(
self,
config_path: Optional[str] = None,
job_name: Optional[str] = None,
strict: Optional[bool] = None,
caller_stack_depth: int = 1,
) -> None:
self._gh_backup = get_gh_backup()
Expand All @@ -69,7 +67,6 @@ def __init__(
calling_module=calling_module,
config_path=config_path,
job_name=job_name,
strict=strict,
)

def __enter__(self, *args: Any, **kwargs: Any) -> None:
Expand Down Expand Up @@ -98,7 +95,6 @@ def __init__(self, config_module: str, job_name: str = "app"):
calling_module=f"{config_module}.{job_name}",
config_path=None,
job_name=job_name,
strict=None,
)

def __enter__(self, *args: Any, **kwargs: Any) -> None:
Expand Down Expand Up @@ -130,9 +126,7 @@ def __init__(self, config_dir: str, job_name: str = "app") -> None:
"initialize_config_dir() requires an absolute config_dir as input"
)
csp = create_config_search_path(search_path_dir=config_dir)
Hydra.create_main_hydra2(
task_name=job_name, config_search_path=csp, strict=None
)
Hydra.create_main_hydra2(task_name=job_name, config_search_path=csp)

def __enter__(self, *args: Any, **kwargs: Any) -> None:
...
Expand Down
5 changes: 0 additions & 5 deletions hydra/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
from .types import TaskFunction


# TODO: remove strict flag (deprecated since Hydra 1.0)
def main(
config_path: Optional[str] = None,
config_name: Optional[str] = None,
strict: Optional[bool] = None,
) -> Callable[[TaskFunction], Any]:
"""
:param config_path: the config path, a directory relative to the declaring python file.
:param config_name: the name of the config (usually the file name without the .yaml extension)
:param strict: (Deprecated) strict mode, will throw an error if command line overrides are not changing an
existing key or if the code is accessing a non existent key
"""

def main_decorator(task_function: TaskFunction) -> Callable[[], None]:
Expand All @@ -35,7 +31,6 @@ def decorated_main(cfg_passthrough: Optional[DictConfig] = None) -> Any:
task_function=task_function,
config_path=config_path,
config_name=config_name,
strict=strict,
)

return decorated_main
Expand Down
2 changes: 1 addition & 1 deletion hydra/plugins/completion_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _query(self, config_name: Optional[str], line: str) -> List[str]:

run_mode = RunMode.MULTIRUN if parsed_args.multirun else RunMode.RUN
config = self.config_loader.load_configuration(
config_name=config_name, overrides=words, run_mode=run_mode, strict=True
config_name=config_name, overrides=words, run_mode=run_mode
)

fname_prefix, filename = CompletionPlugin._get_filename(word)
Expand Down
6 changes: 0 additions & 6 deletions hydra/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(self) -> None:
self.calling_module: Optional[str] = None
self.config_path: Optional[str] = None
self.config_name: Optional[str] = None
self.strict: Optional[bool] = None
self.hydra: Optional[Hydra] = None
self.job_ret: Optional[JobReturn] = None
self.configure_logging: bool = False
Expand All @@ -67,7 +66,6 @@ def __enter__(self) -> "TaskTestFunction":
calling_module=self.calling_module,
config_path=self.config_path,
job_name=job_name,
strict=self.strict,
)
self.temp_dir = tempfile.mkdtemp()
overrides = copy.deepcopy(self.overrides)
Expand Down Expand Up @@ -99,7 +97,6 @@ def __call__(
config_path: Optional[str],
config_name: Optional[str],
overrides: Optional[List[str]] = None,
strict: Optional[bool] = None,
configure_logging: bool = False,
) -> TaskTestFunction:
...
Expand All @@ -121,7 +118,6 @@ def __init__(self) -> None:
self.task_function: Optional[TaskFunction] = None
self.config_path: Optional[str] = None
self.config_name: Optional[str] = None
self.strict: Optional[bool] = None
self.sweeps = None
self.returns = None
self.configure_logging: bool = False
Expand Down Expand Up @@ -152,7 +148,6 @@ def __enter__(self) -> "SweepTaskFunction":
calling_module=self.calling_module,
config_path=self.config_path,
job_name=job_name,
strict=self.strict,
)

self.returns = hydra_.multirun(
Expand Down Expand Up @@ -184,7 +179,6 @@ def __call__(
config_path: Optional[str],
config_name: Optional[str],
overrides: Optional[List[str]],
strict: Optional[bool] = None,
temp_dir: Optional[Path] = None,
) -> SweepTaskFunction:
...
Expand Down
1 change: 0 additions & 1 deletion news/1010.api_change

This file was deleted.

1 change: 1 addition & 0 deletions news/1010.api_change.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Passing a config name as config_path to @hydra.main is now an error
1 change: 1 addition & 0 deletions news/1010.api_change.4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove deprecated strict flag from @hydra.main and the Compose API
12 changes: 0 additions & 12 deletions tests/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ def test_strict_failure_global_strict(
compose(config_file, overrides)


def test_strict_deprecation_warning(hydra_restore_singletons: Any) -> None:
msg = (
"\[email protected](strict) flag is deprecated and will removed in the next version."
"\nSee https://hydra.cc/docs/next/upgrades/0.11_to_1.0/strict_mode_flag_deprecated"
)
with pytest.warns(expected_warning=UserWarning, match=re.escape(msg)):
try:
initialize(config_path=None, strict=True)
finally:
GlobalHydra.instance().clear()


@pytest.mark.usefixtures("hydra_restore_singletons")
@pytest.mark.parametrize(
"config_file, overrides, expected",
Expand Down
Loading