mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
params: use dpath for xpaths (#3531)
Currently `dvc run -p angles` is broken when you use it with `params.yaml`
that looks like this:
```
angles:
- 2
- 3
- 100
- 3.2
- 36.2
- 3.6
```
because we are incorrectly using `flatten` instead of simply using some
xpath-like library to access params that are specified.
This commit is contained in:
@@ -2,9 +2,8 @@ import os
|
||||
import yaml
|
||||
from collections import defaultdict
|
||||
|
||||
import dpath.util
|
||||
from voluptuous import Any
|
||||
from funcy import select_keys
|
||||
from flatten_json import flatten
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.dependency.local import DependencyLOCAL
|
||||
@@ -87,9 +86,10 @@ class DependencyPARAMS(DependencyLOCAL):
|
||||
"Unable to read parameters from '{}'".format(self)
|
||||
) from exc
|
||||
|
||||
config = flatten(config, ".")
|
||||
|
||||
return select_keys(lambda key: key in self.params, config)
|
||||
ret = {}
|
||||
for param in self.params:
|
||||
ret[param] = dpath.util.get(config, param, separator=".")
|
||||
return ret
|
||||
|
||||
def save_info(self):
|
||||
info = self._get_info()
|
||||
|
||||
@@ -81,6 +81,7 @@ install_requires = [
|
||||
"flatten_json>=0.1.6",
|
||||
"texttable>=0.5.2",
|
||||
"pygtrie==2.3.2",
|
||||
"dpath>=2.0.1,<3",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -70,9 +70,11 @@ def test_get_info_unsupported_format(tmp_dir, dvc):
|
||||
|
||||
|
||||
def test_get_info_nested(tmp_dir, dvc):
|
||||
tmp_dir.gen("params.yaml", yaml.dump({"some": {"path": {"foo": "val"}}}))
|
||||
tmp_dir.gen(
|
||||
"params.yaml", yaml.dump({"some": {"path": {"foo": ["val1", "val2"]}}})
|
||||
)
|
||||
dep = DependencyPARAMS(Stage(dvc), None, ["some.path.foo"])
|
||||
assert dep._get_info() == {"some.path.foo": "val"}
|
||||
assert dep._get_info() == {"some.path.foo": ["val1", "val2"]}
|
||||
|
||||
|
||||
def test_save_info_missing_params(dvc):
|
||||
|
||||
Reference in New Issue
Block a user