Skip to content

Commit

Permalink
metrics: Use "metrics.json" as DEFAULT_METRICS_FILE.
Browse files Browse the repository at this point in the history
Closes #6168
  • Loading branch information
daavoo committed Oct 28, 2022
1 parent 4493da0 commit 890fb65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
logger = logging.getLogger(__name__)


DEFAULT_METRICS_FILE = "metrics.json"


def _is_metric(out: Output) -> bool:
return bool(out.metric) or bool(out.live)

Expand All @@ -41,6 +44,13 @@ def _collect_metrics(repo, targets, revision, recursive):
recursive=recursive,
rev=revision,
)
if not targets:
default_metrics = repo.fs.path.join(
repo.root_dir, DEFAULT_METRICS_FILE
)
if default_metrics not in fs_paths and repo.fs.exists(default_metrics):
fs_paths.append(repo.dvcfs.from_os_path(default_metrics))

return _to_fs_paths(metrics) + list(fs_paths)


Expand Down
10 changes: 10 additions & 0 deletions tests/func/metrics/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
from dvc.utils.serialize import JSONFileCorruptedError, YAMLFileCorruptedError


def test_show_default_file(tmp_dir, dvc):
from dvc.repo.metrics.show import DEFAULT_METRICS_FILE

default_file = tmp_dir / DEFAULT_METRICS_FILE
default_file.dump({"foo": 1.0})
assert dvc.metrics.show() == {
"": {"data": {DEFAULT_METRICS_FILE: {"data": {"foo": 1.0}}}}
}


def test_show_simple(tmp_dir, dvc, run_copy_metrics):
tmp_dir.gen("metrics_t.yaml", "1.1")
run_copy_metrics(
Expand Down

0 comments on commit 890fb65

Please sign in to comment.