Skip to content

Commit

Permalink
hydra: resolve OmegaConf interpolations. (#9212)
Browse files Browse the repository at this point in the history
Closes #9196
  • Loading branch information
daavoo authored Mar 20, 2023
1 parent 66406e6 commit 121d56b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dvc/utils/hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def compose_and_dump(
with initialize_config_dir(config_dir, version_base=None):
cfg = compose(config_name=config_name, overrides=overrides)

OmegaConf.resolve(cfg)

suffix = Path(output_file).suffix.lower()
if suffix not in [".yml", ".yaml"]:
dumper = DUMPERS[suffix]
Expand Down
16 changes: 15 additions & 1 deletion tests/func/utils/test_hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_compose_and_dump(tmp_dir, suffix, overrides, expected):


def test_compose_and_dump_yaml_handles_string(tmp_dir):
"""Regression test for 8583"""
"""Regression test for https://github.com/iterative/dvc/issues/8583"""
from dvc.utils.hydra import compose_and_dump

config = tmp_dir / "conf" / "config.yaml"
Expand All @@ -189,6 +189,20 @@ def test_compose_and_dump_yaml_handles_string(tmp_dir):
assert output_file.read_text() == "foo: 'no'\n"


def test_compose_and_dump_resolves_interpolation(tmp_dir):
"""Regression test for https://github.com/iterative/dvc/issues/9196"""
from dvc.utils.hydra import compose_and_dump

config = tmp_dir / "conf" / "config.yaml"
config.parent.mkdir()
config.dump({"data": {"root": "path/to/root", "raw": "${.root}/raw"}})
output_file = tmp_dir / "params.yaml"
compose_and_dump(output_file, str(config.parent), "config", [])
assert output_file.parse() == {
"data": {"root": "path/to/root", "raw": "path/to/root/raw"}
}


@pytest.mark.parametrize(
"overrides, expected",
[
Expand Down

0 comments on commit 121d56b

Please sign in to comment.