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
9 changes: 7 additions & 2 deletions dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def diff(self, *args, **kwargs):
def modify(self, path, props=None, unset=None):
from dvc.dvcfile import Dvcfile

props = props or {}
template = props.get("template")
if template:
self.repo.plot_templates.get_template(template)

(out,) = self.repo.find_outs_by_path(path)

# This out will become a plot unless it is one already
Expand All @@ -92,7 +97,7 @@ def modify(self, path, props=None, unset=None):

for field in unset or ():
out.plot.pop(field, None)
out.plot.update(props or {})
out.plot.update(props)

# Empty dict will move it to non-plots
if not out.plot:
Expand All @@ -101,7 +106,7 @@ def modify(self, path, props=None, unset=None):
out.verify_metric()

dvcfile = Dvcfile(self.repo, out.stage.path)
dvcfile.dump(out.stage, update_pipeline=True)
dvcfile.dump(out.stage, update_pipeline=True, no_lock=True)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

plots modify should not try to generate lockfile.



def _collect_plots(repo, targets=None, rev=None):
Expand Down
4 changes: 2 additions & 2 deletions tests/func/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

@pytest.fixture
def run_copy_metrics(tmp_dir, run_copy):
def run(file1, file2, commit=None, tag=None, **kwargs):
def run(file1, file2, commit=None, tag=None, single_stage=True, **kwargs):
Copy link
Copy Markdown
Collaborator Author

@skshetry skshetry Jun 9, 2020

Choose a reason for hiding this comment

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

Need to fix these ugly hacks: singele_stage being the default, later.

stage = tmp_dir.dvc.run(
cmd=f"python copy.py {file1} {file2}",
deps=[file1],
single_stage=True,
single_stage=single_stage,
**kwargs,
)

Expand Down
47 changes: 47 additions & 0 deletions tests/func/plots/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import yaml
from funcy import first

from dvc.dvcfile import PIPELINE_LOCK
from dvc.repo.plots.data import (
JSONPlotData,
NoMetricInHistoryError,
Expand All @@ -17,6 +18,7 @@
YAMLPlotData,
)
from dvc.repo.plots.template import NoFieldInDataError, TemplateNotFoundError
from dvc.utils import relpath


def _write_csv(metric, filename, header=True):
Expand Down Expand Up @@ -538,3 +540,48 @@ def test_load_metric_from_dict_yaml(tmp_dir):
d["rev"] = "revision"

assert list(map(dict, plot_data.to_datapoints())) == expected


def test_plots_modify_existing_template(
tmp_dir, dvc, run_copy_metrics, custom_template
):
metric = [{"a": 1, "b": 2}, {"a": 2, "b": 3}]
_write_json(tmp_dir, metric, "metric_t.json")
stage = run_copy_metrics(
"metric_t.json",
"metric.json",
plots_no_cache=["metric.json"],
name="copy-metrics",
single_stage=False,
)
dvc.plots.modify(
"metric.json", props={"template": relpath(custom_template)}
)
stage = stage.reload()
assert stage.outs[0].plot == {"template": relpath(custom_template)}


def test_plots_modify_should_not_change_lockfile(
tmp_dir, dvc, run_copy_metrics, custom_template
):
_write_json(tmp_dir, [{"a": 1, "b": 2}], "metric_t.json")
run_copy_metrics(
"metric_t.json",
"metric.json",
plots_no_cache=["metric.json"],
name="copy-metrics",
single_stage=False,
)

(tmp_dir / PIPELINE_LOCK).unlink()
dvc.plots.modify(
"metric.json", props={"template": relpath(custom_template)}
)
assert not (tmp_dir / PIPELINE_LOCK).exists()
Comment thread
skshetry marked this conversation as resolved.


def test_plots_modify_not_existing_template(dvc):
with pytest.raises(TemplateNotFoundError):
dvc.plots.modify(
"metric.json", props={"template": "not-existing-template.json"}
)