Skip to content
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
10 changes: 6 additions & 4 deletions dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ def _read_metrics(repo, metrics, rev, onerror=None):

res = {}
for metric in metrics:
rel_metric_path = os.path.join(relpath, *fs.path.parts(metric))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.path.join? As I recall one of the problems is windows behavior. dvcfs utlizizes posixpath.

Copy link
Contributor Author

@daavoo daavoo Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um. Some unit tests are failing with fs.path.join.
os.path.join did solve the original issue.
@pared I wonder if this would be a breaking change for windows 🤔 (and potentially vscode?) as we would be changing the returned path format. So anything relying on json output would get different keys after this merge

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, metrics results are relying on os specific paths. I wonder if that won't be problematic in the future. In plots we are heavily relying on fs.path. This is inconsistent, we might need to consider unifying it at some point.

if not fs.isfile(metric):
continue
if fs.isfile(rel_metric_path):
metric = rel_metric_path
else:
continue

res[os.path.join(relpath, *fs.path.parts(metric))] = _read_metric(
metric, fs, rev, onerror=onerror
)
res[rel_metric_path] = _read_metric(metric, fs, rev, onerror=onerror)

return res

Expand Down
26 changes: 26 additions & 0 deletions tests/func/metrics/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@ def test_show_simple(tmp_dir, dvc, run_copy_metrics):
}


def test_show_simple_from_subdir(tmp_dir, dvc, run_copy_metrics):
subdir = tmp_dir / "subdir"
subdir.mkdir()
tmp_dir.gen("metrics_t.yaml", "1.1")
run_copy_metrics(
"metrics_t.yaml",
"subdir/metrics.yaml",
metrics=["subdir/metrics.yaml"],
)

expected_path = os.path.join("subdir", "metrics.yaml")
assert dvc.metrics.show() == {"": {"data": {expected_path: {"data": 1.1}}}}

expected_path = os.path.join("..", "subdir", "metrics.yaml")
with subdir.chdir():
assert dvc.metrics.show() == {
"": {"data": {expected_path: {"data": 1.1}}}
}
subdir2 = tmp_dir / "subdir2"
subdir2.mkdir()
with subdir2.chdir():
assert dvc.metrics.show() == {
"": {"data": {expected_path: {"data": 1.1}}}
}


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