Skip to content

Commit

Permalink
add toml support to dvc show
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Trifirò committed Jul 22, 2020
1 parent d77b233 commit edebcb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dvc/repo/params/show.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

import toml
import yaml

from dvc.dependency.param import ParamsDependency
Expand Down Expand Up @@ -34,8 +35,10 @@ def _read_params(repo, configs, rev):

with repo.tree.open(config, "r") as fobj:
try:
res[str(config)] = yaml.safe_load(fobj)
except yaml.YAMLError:
res[str(config)] = ParamsDependency.PARAMS_FILE_LOADERS[
config.suffix.lower()
](fobj)
except (yaml.YAMLError, toml.TomlDecodeError):
logger.debug(
"failed to read '%s' on '%s'", config, rev, exc_info=True
)
Expand Down
10 changes: 10 additions & 0 deletions tests/func/params/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ def test_show(tmp_dir, dvc):
assert dvc.params.show() == {"": {"params.yaml": {"foo": "bar"}}}


def test_show_toml(tmp_dir, dvc):
tmp_dir.gen("params.toml", "[foo]\nbar = 42\nbaz = [1, 2]\n")
dvc.run(
cmd="echo params.toml", params=["params.toml:foo"], single_stage=True
)
assert dvc.params.show() == {
"": {"params.toml": {"foo": {"bar": 42, "baz": [1, 2]}}}
}


def test_show_multiple(tmp_dir, dvc):
tmp_dir.gen("params.yaml", "foo: bar\nbaz: qux\n")
dvc.run(
Expand Down

0 comments on commit edebcb4

Please sign in to comment.