Skip to content

Commit

Permalink
exp show: Include outs in --json output.
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Jan 26, 2022
1 parent 1a1e282 commit 5e80fcc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
15 changes: 14 additions & 1 deletion dvc/repo/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def _collect_experiment_commit(
running=None,
onerror: Optional[Callable] = None,
):
from dvc.dependency import ParamsDependency, RepoDependency

res: Dict[str, Optional[Any]] = defaultdict(dict)
for rev in repo.brancher(revs=[exp_rev]):
if rev == "workspace":
Expand All @@ -46,7 +48,17 @@ def _collect_experiment_commit(
"nfiles": dep.meta.nfiles,
}
for dep in repo.index.deps
if type(dep).__name__ != "ParamsDependency" and dep.is_in_repo
if not isinstance(dep, (ParamsDependency, RepoDependency))
}

res["outs"] = {
out.def_path: {
"hash": out.hash_info.value,
"size": out.meta.size,
"nfiles": out.meta.nfiles,
}
for out in repo.index.outs
if not (out.is_metric or out.is_plot)
}

res["queued"] = stash
Expand Down Expand Up @@ -121,6 +133,7 @@ def show(
param_deps=False,
onerror: Optional[Callable] = None,
):

if onerror is None:
onerror = onerror_collect

Expand Down
43 changes: 42 additions & 1 deletion tests/func/experiments/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def make_executor_info(**kwargs):


def test_show_simple(tmp_dir, scm, dvc, exp_stage):
print(dvc.experiments.show()["workspace"])
assert dvc.experiments.show()["workspace"] == {
"baseline": {
"data": {
Expand All @@ -48,6 +47,7 @@ def test_show_simple(tmp_dir, scm, dvc, exp_stage):
}
},
"metrics": {"metrics.yaml": {"data": {"foo": 1}}},
"outs": {},
"params": {"params.yaml": {"data": {"foo": 1}}},
"queued": False,
"running": False,
Expand Down Expand Up @@ -80,6 +80,7 @@ def test_show_experiment(tmp_dir, scm, dvc, exp_stage, workspace):
}
},
"metrics": {"metrics.yaml": {"data": {"foo": 1}}},
"outs": {},
"params": {"params.yaml": {"data": {"foo": 1}}},
"queued": False,
"running": False,
Expand Down Expand Up @@ -343,6 +344,7 @@ def test_show_running_workspace(tmp_dir, scm, dvc, exp_stage, capsys):
},
"metrics": {"metrics.yaml": {"data": {"foo": 1}}},
"params": {"params.yaml": {"data": {"foo": 1}}},
"outs": {},
"queued": False,
"running": True,
"executor": info.location,
Expand Down Expand Up @@ -619,3 +621,42 @@ def test_show_parallel_coordinates(tmp_dir, dvc, scm, mocker, capsys):
html_text = (tmp_dir / "dvc_plots" / "index.html").read_text()
assert '"label": "Created"' not in html_text
assert '"label": "foobar"' not in html_text


def test_show_outs(tmp_dir, dvc, scm):
tmp_dir.gen("copy.py", COPY_SCRIPT)
params_file = tmp_dir / "params.yaml"
params_data = {
"foo": 1,
"bar": 1,
}
(tmp_dir / params_file).dump(params_data)

dvc.run(
cmd="python copy.py params.yaml metrics.yaml && echo out > out",
metrics_no_cache=["metrics.yaml"],
params=["foo", "bar"],
name="copy-file",
deps=["copy.py"],
outs=["out"],
)
scm.add(
[
"dvc.yaml",
"dvc.lock",
"copy.py",
"params.yaml",
"metrics.yaml",
".gitignore",
]
)
scm.commit("init")

outs = dvc.experiments.show()["workspace"]["baseline"]["data"]["outs"]
assert outs == {
"out": {
"hash": ANY,
"size": ANY,
"nfiles": None,
}
}

0 comments on commit 5e80fcc

Please sign in to comment.