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:
Ruslan Kuprieiev
2020-03-25 06:17:09 +02:00
committed by GitHub
parent 0bf6fdae14
commit 9de8d1e0fa
3 changed files with 10 additions and 7 deletions
+5 -5
View File
@@ -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()
+1
View File
@@ -81,6 +81,7 @@ install_requires = [
"flatten_json>=0.1.6",
"texttable>=0.5.2",
"pygtrie==2.3.2",
"dpath>=2.0.1,<3",
]
+4 -2
View File
@@ -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):