-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Simpler param updates with python-benedict #4780
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ def _parse_params(path_params: Iterable): | |
| from ruamel.yaml import YAMLError | ||
|
|
||
| from dvc.dependency.param import ParamsDependency | ||
| from dvc.utils.flatten import unflatten | ||
| from dvc.utils.serialize import loads_yaml | ||
|
|
||
| ret = {} | ||
|
|
@@ -31,7 +30,7 @@ def _parse_params(path_params: Iterable): | |
| ) | ||
| if not path: | ||
| path = ParamsDependency.DEFAULT_PARAMS_FILE | ||
| ret[path] = unflatten(params) | ||
| ret[path] = params | ||
|
||
| return ret | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,7 @@ def run(self): | |
| "shtab>=1.3.2,<2", | ||
| "rich>=3.0.5", | ||
| "dictdiffer>=0.8.1", | ||
| "python-benedict>=0.21.1", | ||
| ] | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,27 +66,45 @@ def test_update_with_pull(tmp_dir, scm, dvc, exp_stage, mocker): | |
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "change, expected", | ||
| "changes, expected", | ||
| [ | ||
| ["foo.1.baz=3", "foo: [bar: 1, baz: 3]"], | ||
| ["foo.0=bar", "foo: [bar, baz: 2]"], | ||
| ["foo.1=- baz\n- goo", "foo: [bar: 1, [baz, goo]]"], | ||
| [["foo=baz"], "{foo: baz, goo: {bag: 3}, lorem: false}"], | ||
| [["foo=baz,goo=bar"], "{foo: baz, goo: bar, lorem: false}"], | ||
| [ | ||
| ["goo.bag=4"], | ||
| "{foo: [bar: 1, baz: 2], goo: {bag: 4}, lorem: false}", | ||
| ], | ||
| [["foo[0]=bar"], "{foo: [bar, baz: 2], goo: {bag: 3}, lorem: false}"], | ||
| [ | ||
| ["foo[1].baz=3"], | ||
| "{foo: [bar: 1, baz: 3], goo: {bag: 3}, lorem: false}", | ||
| ], | ||
| [ | ||
| ["foo[1]=- baz\n- goo"], | ||
|
||
| "{foo: [bar: 1, [baz, goo]], goo: {bag: 3}, lorem: false}", | ||
| ], | ||
| [ | ||
| ["lorem.ipsum=3"], | ||
| "{foo: [bar: 1, baz: 2], goo: {bag: 3}, lorem: {ipsum: 3}}", | ||
| ], | ||
| ], | ||
| ) | ||
| def test_modify_list_param(tmp_dir, scm, dvc, mocker, change, expected): | ||
| def test_modify_params(tmp_dir, scm, dvc, mocker, changes, expected): | ||
| tmp_dir.gen("copy.py", COPY_SCRIPT) | ||
| tmp_dir.gen("params.yaml", "foo: [bar: 1, baz: 2]") | ||
| tmp_dir.gen( | ||
| "params.yaml", "{foo: [bar: 1, baz: 2], goo: {bag: 3}, lorem: false}" | ||
| ) | ||
| stage = dvc.run( | ||
| cmd="python copy.py params.yaml metrics.yaml", | ||
| metrics_no_cache=["metrics.yaml"], | ||
| params=["foo"], | ||
| params=["foo", "goo", "lorem"], | ||
| name="copy-file", | ||
| ) | ||
| scm.add(["dvc.yaml", "dvc.lock", "copy.py", "params.yaml", "metrics.yaml"]) | ||
| scm.commit("init") | ||
|
|
||
| new_mock = mocker.spy(dvc.experiments, "new") | ||
| dvc.experiments.run(stage.addressing, params=[change]) | ||
| dvc.experiments.run(stage.addressing, params=changes) | ||
|
|
||
| new_mock.assert_called_once() | ||
| assert ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if you prefer local or global imports. Since this is only needed for the beta experiments feature, I figured local was appropriate.