Skip to content

metrics: skip missing metrics silently #4130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ def _read_metrics(repo, metrics, rev):
if not tree.exists(metric):
continue

with tree.open(metric, "r") as fobj:
try:
try:
with tree.open(metric, "r") as fobj:
# NOTE this also supports JSON
val = yaml.safe_load(fobj)
except yaml.YAMLError:
logger.debug(
"failed to read '%s' on '%s'", metric, rev, exc_info=True
)
continue
except (FileNotFoundError, yaml.YAMLError):
logger.debug(
"failed to read '%s' on '%s'", metric, rev, exc_info=True
)
continue

val = _extract_metrics(val)
if val:
res[str(metric)] = val
val = _extract_metrics(val)
if val:
res[str(metric)] = val

return res

Expand Down
17 changes: 17 additions & 0 deletions tests/func/metrics/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dvc.repo import Repo
from dvc.repo.metrics.show import NoMetricsError
from dvc.utils.fs import remove


def test_show_empty(dvc):
Expand Down Expand Up @@ -93,3 +94,19 @@ def test_show_subrepo_with_preexisting_tags(tmp_dir, scm):
"workspace": {expected_path: {"foo": 1}},
"v1": {expected_path: {"foo": 1}},
}


def test_missing_cache(tmp_dir, dvc, run_copy_metrics):
tmp_dir.gen("metrics_t.yaml", "1.1")
run_copy_metrics(
"metrics_t.yaml", "metrics.yaml", metrics=["metrics.yaml"],
)

# This one should be skipped
stage = run_copy_metrics(
"metrics_t.yaml", "metrics2.yaml", metrics=["metrics2.yaml"],
)
remove(stage.outs[0].fspath)
remove(stage.outs[0].cache_path)

assert dvc.metrics.show() == {"": {"metrics.yaml": 1.1}}