mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
plots: Fix match_defs_renderers when plots are defined in nt format.
`plots.show` returned `definitions` in native `nt` format but sources in `posixpath` format so the matching was failing. Closes #8689 - Add `test_show_plots_defined_with_native_os_path`.
This commit is contained in:
+9
-5
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from collections import defaultdict
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional
|
||||
|
||||
@@ -5,7 +6,7 @@ import dpath
|
||||
import dpath.options
|
||||
from funcy import last
|
||||
|
||||
from dvc.repo.plots import infer_data_sources
|
||||
from dvc.repo.plots import _normpath, infer_data_sources
|
||||
from dvc.utils.plots import get_plot_id
|
||||
|
||||
from .convert import _get_converter
|
||||
@@ -43,17 +44,20 @@ class PlotsData:
|
||||
|
||||
def get_definition_data(self, target_files, rev):
|
||||
result = {}
|
||||
for file in target_files:
|
||||
for definition_file in target_files:
|
||||
if os.name == "nt":
|
||||
source_file = _normpath(definition_file).replace("\\", "/")
|
||||
else:
|
||||
source_file = definition_file
|
||||
file_content = (
|
||||
self.data.get(rev, {})
|
||||
.get("sources", {})
|
||||
.get("data", {})
|
||||
.get(file, {})
|
||||
.get(source_file, {})
|
||||
.get("data", {})
|
||||
)
|
||||
if file_content:
|
||||
result[file] = file_content
|
||||
|
||||
result[definition_file] = file_content
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import pytest
|
||||
@@ -389,3 +390,33 @@ def test_top_level_plots(
|
||||
assert content == get_plot(result, "workspace", file=filename)
|
||||
else:
|
||||
assert filename not in get_plot(result, "workspace")
|
||||
|
||||
|
||||
def test_show_plots_defined_with_native_os_path(tmp_dir, dvc, scm, capsys):
|
||||
"""Regression test for #8689"""
|
||||
top_level_plot = os.path.join("subdir", "top_level_plot.csv")
|
||||
stage_plot = os.path.join("subdir", "stage_plot.csv")
|
||||
(tmp_dir / "subdir").mkdir()
|
||||
(tmp_dir / top_level_plot).write_text("foo,bar\n1,2")
|
||||
(tmp_dir / stage_plot).write_text("foo,bar\n1,2")
|
||||
(tmp_dir / "dvc.yaml").dump({"plots": [top_level_plot]})
|
||||
|
||||
dvc.stage.add(name="foo", plots=[stage_plot], cmd="echo foo")
|
||||
|
||||
plots = dvc.plots.show()
|
||||
|
||||
# sources are in posixpath format
|
||||
sources = plots["workspace"]["sources"]["data"]
|
||||
assert sources["subdir/top_level_plot.csv"]["data"] == [{"foo": "1", "bar": "2"}]
|
||||
assert sources["subdir/stage_plot.csv"]["data"] == [{"foo": "1", "bar": "2"}]
|
||||
# definitions are in native os format
|
||||
definitions = plots["workspace"]["definitions"]["data"]
|
||||
assert top_level_plot in definitions["dvc.yaml"]["data"]
|
||||
assert stage_plot in definitions[""]["data"]
|
||||
|
||||
capsys.readouterr()
|
||||
assert main(["plots", "show", "--json"]) == 0
|
||||
out, _ = capsys.readouterr()
|
||||
json_out = json.loads(out)
|
||||
assert json_out[f"dvc.yaml::{top_level_plot}"]
|
||||
assert json_out[stage_plot]
|
||||
|
||||
Reference in New Issue
Block a user