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
8 changes: 8 additions & 0 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ def __init__(self):
)


class NoPlotsError(DvcException):
def __init__(self):
super().__init__(
"no plots in this repository. Use `--plots/--plots-no-cache` "
"options for `dvc run` to mark stage outputs as plots."
)


class YAMLFileCorruptedError(DvcException):
def __init__(self, path):
path = relpath(path)
Expand Down
11 changes: 9 additions & 2 deletions dvc/repo/plots/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from funcy import first, last, project

from dvc.exceptions import DvcException
from dvc.exceptions import DvcException, NoPlotsError
from dvc.repo import locked
from dvc.schema import PLOT_PROPS

Expand Down Expand Up @@ -108,6 +108,9 @@ def _show(repo, datafile=None, revs=None, props=None):
if revs is None:
revs = ["workspace"]

if props is None:
props = {}

if not datafile and not props.get("template"):
raise NoDataOrTemplateProvided()

Expand Down Expand Up @@ -201,7 +204,11 @@ def show(repo, targets=None, revs=None, props=None) -> dict:
if targets:
raise NoMetricInHistoryError(", ".join(targets))

datafile, plot = _show(repo, datafile=None, revs=revs, props=props)
try:
datafile, plot = _show(repo, datafile=None, revs=revs, props=props)
except NoDataOrTemplateProvided:
raise NoPlotsError()

return {datafile: plot}

return {
Expand Down
7 changes: 4 additions & 3 deletions tests/func/plots/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
PlotData,
PlotMetricTypeError,
)
from dvc.repo.plots.show import NoDataOrTemplateProvided
from dvc.repo.plots.template import (
NoDataForTemplateError,
NoFieldInDataError,
Expand Down Expand Up @@ -457,8 +456,10 @@ def test_plot_override_specified_data_source(
assert plot_content["encoding"]["y"]["field"] == "b"


def test_should_raise_on_no_template_and_datafile(tmp_dir, dvc):
with pytest.raises(NoDataOrTemplateProvided):
def test_no_plots(tmp_dir, dvc):
from dvc.exceptions import NoPlotsError

with pytest.raises(NoPlotsError):
dvc.plots.show()


Expand Down