Skip to content

Commit

Permalink
Updated examples to reflect composite config_path deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed May 24, 2020
1 parent f98f42f commit 3f6ce61
Show file tree
Hide file tree
Showing 30 changed files with 55 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/advanced/hydra_app_example/hydra_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import hydra


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def main(cfg: DictConfig) -> None:
print(cfg.pretty())

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/ray_example/ray_compose_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def train(overrides: List[str], cfg: DictConfig) -> Tuple[List[str], float]:
return overrides, 0.9


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def main(cfg: DictConfig) -> None:
ray.init(**cfg.ray.init)

Expand Down
2 changes: 1 addition & 1 deletion examples/configure_hydra/custom_help/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
print(cfg.pretty())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from hydra.core.hydra_config import HydraConfig


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def experiment(_cfg: DictConfig) -> None:
print(HydraConfig.get().job.name)

Expand Down
2 changes: 1 addition & 1 deletion examples/configure_hydra/logging/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
log = logging.getLogger(__name__)


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(_cfg: DictConfig) -> None:
log.info("Info level message")

Expand Down
2 changes: 1 addition & 1 deletion examples/configure_hydra/workdir/custom_workdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import hydra


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def experiment(_cfg: DictConfig) -> None:
print(os.getcwd())

Expand Down
2 changes: 1 addition & 1 deletion examples/patterns/objects/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def connect(self) -> None:
)


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
connection = hydra.utils.instantiate(cfg.db)
connection.connect()
Expand Down
2 changes: 1 addition & 1 deletion examples/patterns/specializing_config/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
log = logging.getLogger(__name__)


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def experiment(cfg: DictConfig) -> None:
print(cfg.pretty())

Expand Down
9 changes: 5 additions & 4 deletions hydra/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ def split_config_path(
# assuming dir/config.yaml form
config_file: Optional[str] = basename(config_path)
config_dir: Optional[str] = dirname(config_path)
msg = (
"\nUsing config_path to specify the config name is deprecated, specify the config name via config_name"
"\nSee https://hydra.cc/next/upgrades/0.11_to_1.0/config_path_changes"
)
warnings.warn(
category=UserWarning,
message="\nUsing config_path to specify the config name is deprecated, "
"specify the config name via config_name"
"\nSee https://hydra.cc/next/upgrades/0.11_to_1.0/config_path_changes",
category=UserWarning, message=msg,
)
else:
# assuming dir form without a config file.
Expand Down
2 changes: 1 addition & 1 deletion hydra/test_utils/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="configs/completion_test/config.yaml")
@hydra.main(config_path="configs/completion_test", config_name="config")
def run_cli(cfg: DictConfig) -> None:
print(cfg.pretty())

Expand Down
4 changes: 2 additions & 2 deletions hydra/test_utils/launcher_common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def sweep_2_jobs(
calling_file=None,
calling_module="hydra.test_utils.a_module",
task_function=task_function,
config_path="configs/compose.yaml",
config_name=None,
config_path="configs",
config_name="compose",
overrides=overrides,
)
base_cfg = {"foo": 10, "bar": 100, "a": 0}
Expand Down
8 changes: 4 additions & 4 deletions hydra/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def integration_test(
$PROLOG
@hydra.main($CONFIG_PATH)
@hydra.main($CONFIG_NAME)
def experiment(cfg):
with open("$OUTPUT_FILE", "w") as f:
$PRINTS
Expand All @@ -307,19 +307,19 @@ def experiment(cfg):
print_code = _get_statements(indent=" ", statements=prints)
prolog_code = _get_statements(indent="", statements=prolog)

config_path = ""
config_name = ""
if task_config is not None:
cfg_file = tmpdir / "config.yaml"
with open(str(cfg_file), "w") as f:
f.write("# @package _global_\n")
OmegaConf.save(task_config, f)
config_path = "config_path='config.yaml'"
config_name = "config_name='config'"
output_file = str(tmpdir / "output.txt")
# replace Windows path separator \ with an escaped version \\
output_file = output_file.replace("\\", "\\\\")
code = s.substitute(
PRINTS=print_code,
CONFIG_PATH=config_path,
CONFIG_NAME=config_name,
OUTPUT_FILE=output_file,
PROLOG=prolog_code,
)
Expand Down
2 changes: 1 addition & 1 deletion plugins/examples/example_launcher_plugin/example/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hydra


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg):
print(cfg.pretty())

Expand Down
2 changes: 1 addition & 1 deletion plugins/examples/example_sweeper_plugin/example/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hydra


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg):
print(cfg.pretty())

Expand Down
2 changes: 1 addition & 1 deletion plugins/hydra_ax_sweeper/example/banana.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
log = logging.getLogger(__name__)


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def banana(cfg: DictConfig) -> Any:
x = cfg.banana.x
y = cfg.banana.y
Expand Down
2 changes: 1 addition & 1 deletion plugins/hydra_ax_sweeper/tests/apps/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from omegaconf import DictConfig


@hydra.main(config_path="polynomial.yaml")
@hydra.main(config_name="polynomial")
def polynomial(cfg: DictConfig) -> Any:
x = cfg.polynomial.x
y = cfg.polynomial.y
Expand Down
2 changes: 1 addition & 1 deletion plugins/hydra_colorlog/example/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
log = logging.getLogger(__name__)


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def my_app(_cfg):
log.debug("Debug level message")
log.info("Info level message")
Expand Down
2 changes: 1 addition & 1 deletion plugins/hydra_joblib_launcher/example/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
log = logging.getLogger(__name__)


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def my_app(cfg):
log.info(f"Process ID {os.getpid()} executing task {cfg.task} ...")

Expand Down
2 changes: 1 addition & 1 deletion plugins/hydra_nevergrad_sweeper/example/dummy_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
log = logging.getLogger(__name__)


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def dummy_training(cfg: DictConfig) -> float:
"""A dummy function to minimize
Minimum is 0.0 at:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/app_with_cfg/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def my_app(_: DictConfig) -> None:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/app_with_cfg_groups/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(_: DictConfig) -> None:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/app_with_config_with_free_group/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(_: DictConfig) -> None:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/app_with_custom_launcher/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def my_app(_: DictConfig) -> None:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/app_with_split_cfg/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def my_app(_: DictConfig) -> None:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/interpolating_dir_hydra_to_app/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def my_app(_: DictConfig) -> None:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/setting_env/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import hydra


@hydra.main(config_path="config.yaml")
@hydra.main(config_name="config")
def my_app(_: DictConfig) -> None:
print(f"foo={os.environ['foo']}")
print(f"bar={os.environ['bar']}")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/sweep_complex_defaults/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hydra


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(_cfg: DictConfig) -> None:
print(_cfg.pretty())

Expand Down
30 changes: 18 additions & 12 deletions tests/test_hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test_missing_conf_file(
with task_runner(
calling_file=calling_file,
calling_module=calling_module,
config_path="not_found.yaml",
config_name=None,
config_path=None,
config_name="not_found.yaml",
):
pass

Expand Down Expand Up @@ -207,18 +207,24 @@ def test_app_with_config_path_backward_compatibility(
calling_file: str,
calling_module: str,
) -> None:
task = task_runner(
calling_file=calling_file,
calling_module=calling_module,
config_path="conf/config.yaml", # Testing legacy mode, both path and named are in config_path
config_name=None,
msg = (
"\nUsing config_path to specify the config name is deprecated, specify the config name via config_name"
"\nSee https://hydra.cc/next/upgrades/0.11_to_1.0/config_path_changes"
)
with task:
assert task.job_ret is not None and task.job_ret.cfg == {
"optimizer": {"type": "nesterov", "lr": 0.001}
}

verify_dir_outputs(task.job_ret)
with pytest.warns(expected_warning=UserWarning, match=re.escape(msg)):
task = task_runner(
calling_file=calling_file,
calling_module=calling_module,
config_path="conf/config.yaml", # Testing legacy mode, both path and named are in config_path
config_name=None,
)
with task:
assert task.job_ret is not None and task.job_ret.cfg == {
"optimizer": {"type": "nesterov", "lr": 0.001}
}

verify_dir_outputs(task.job_ret)


@pytest.mark.parametrize( # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion website/docs/experimental/ray_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def train(overrides, cfg):
return overrides, 0.9


@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def main(cfg):
ray.init(**cfg.ray.init)

Expand Down
2 changes: 1 addition & 1 deletion website/docs/patterns/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ db:

With this, you can instantiate the object from the configuration with a single line of code:
```python
@hydra.main(config_path="conf/config.yaml")
@hydra.main(config_path="conf", config_name="config")
def my_app(cfg):
connection = hydra.utils.instantiate(cfg.db)
connection.connect()
Expand Down

0 comments on commit 3f6ce61

Please sign in to comment.