Skip to content

Commit

Permalink
exp: show: Include additional info in --json.
Browse files Browse the repository at this point in the history
Use relpath to repo.root_dir as keys in deps and outs.
Add `use_cache` and `is_data_source` for outs.

This allows to differentiate git-tracked dependencies and
intermediate outputs.

Closes #7575
Closes #7790
  • Loading branch information
daavoo committed May 25, 2022
1 parent dae0000 commit 34ef180
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
9 changes: 5 additions & 4 deletions dvc/repo/experiments/show.py
Expand Up @@ -7,7 +7,7 @@
from dvc.repo.metrics.show import _gather_metrics
from dvc.repo.params.show import _gather_params
from dvc.scm import iter_revs
from dvc.utils import error_handler, onerror_collect
from dvc.utils import error_handler, onerror_collect, relpath

if TYPE_CHECKING:
from dvc.repo import Repo
Expand Down Expand Up @@ -45,20 +45,21 @@ def _collect_experiment_commit(
res["params"] = params

res["deps"] = {
dep.def_path: {
relpath(dep.fs_path, repo.root_dir): {
"hash": dep.hash_info.value,
"size": dep.meta.size,
"nfiles": dep.meta.nfiles,
}
for dep in repo.index.deps
if not isinstance(dep, (ParamsDependency, RepoDependency))
}

res["outs"] = {
out.def_path: {
relpath(out.fs_path, repo.root_dir): {
"hash": out.hash_info.value,
"size": out.meta.size,
"nfiles": out.meta.nfiles,
"use_cache": out.use_cache,
"is_data_source": out.stage.is_data_source,
}
for out in repo.index.outs
if not (out.is_metric or out.is_plot)
Expand Down
62 changes: 61 additions & 1 deletion tests/func/experiments/test_show.py
Expand Up @@ -34,6 +34,7 @@ def make_executor_info(**kwargs):
return ExecutorInfo(**kwargs)


@pytest.mark.vscode
def test_show_simple(tmp_dir, scm, dvc, exp_stage):
assert dvc.experiments.show()["workspace"] == {
"baseline": {
Expand All @@ -57,6 +58,7 @@ def test_show_simple(tmp_dir, scm, dvc, exp_stage):
}


@pytest.mark.vscode
@pytest.mark.parametrize("workspace", [True, False])
def test_show_experiment(tmp_dir, scm, dvc, exp_stage, workspace):
baseline_rev = scm.get_rev()
Expand Down Expand Up @@ -101,6 +103,7 @@ def test_show_experiment(tmp_dir, scm, dvc, exp_stage, workspace):
assert exp["data"]["params"]["params.yaml"] == expected_params


@pytest.mark.vscode
def test_show_queued(tmp_dir, scm, dvc, exp_stage):
baseline_rev = scm.get_rev()

Expand Down Expand Up @@ -132,6 +135,7 @@ def test_show_queued(tmp_dir, scm, dvc, exp_stage):
assert exp["params"]["params.yaml"] == {"data": {"foo": 3}}


@pytest.mark.vscode
@pytest.mark.parametrize("workspace", [True, False])
def test_show_checkpoint(
tmp_dir, scm, dvc, checkpoint_stage, capsys, workspace
Expand Down Expand Up @@ -169,6 +173,7 @@ def test_show_checkpoint(
assert f"{fs} {name}" in cap.out


@pytest.mark.vscode
@pytest.mark.parametrize("workspace", [True, False])
def test_show_checkpoint_branch(
tmp_dir, scm, dvc, checkpoint_stage, capsys, workspace
Expand Down Expand Up @@ -281,6 +286,7 @@ def test_show_filter(
assert "Experiment" not in cap.out


@pytest.mark.vscode
def test_show_multiple_commits(tmp_dir, scm, dvc, exp_stage):
init_rev = scm.get_rev()
tmp_dir.scm_gen("file", "file", "commit")
Expand Down Expand Up @@ -318,6 +324,7 @@ def test_show_sort(tmp_dir, scm, dvc, exp_stage, caplog):
)


@pytest.mark.vscode
def test_show_running_workspace(tmp_dir, scm, dvc, exp_stage, capsys):
pid_dir = os.path.join(dvc.tmp_dir, EXEC_TMP_DIR, EXEC_PID_DIR)
info = make_executor_info(location=BaseExecutor.DEFAULT_LOCATION)
Expand Down Expand Up @@ -626,7 +633,8 @@ def test_show_parallel_coordinates(tmp_dir, dvc, scm, mocker, capsys):
assert '"label": "Experiment"' not in html_text


def test_show_outs(tmp_dir, dvc, scm):
@pytest.mark.vscode
def test_show_outs(tmp_dir, dvc, scm, erepo_dir):
tmp_dir.gen("copy.py", COPY_SCRIPT)
params_file = tmp_dir / "params.yaml"
params_data = {
Expand All @@ -652,9 +660,61 @@ def test_show_outs(tmp_dir, dvc, scm):
"hash": ANY,
"size": ANY,
"nfiles": None,
"use_cache": True,
"is_data_source": False,
}
}

tmp_dir.dvc_gen("out_add", "foo", commit="dvc add output")

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

with erepo_dir.chdir():
erepo_dir.dvc_gen("out", "out content", commit="create out")

dvc.imp(os.fspath(erepo_dir), "out", "out_imported")

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


def test_metrics_renaming(tmp_dir, dvc, scm, capsys):
tmp_dir.gen("copy.py", COPY_SCRIPT)
Expand Down

0 comments on commit 34ef180

Please sign in to comment.