exit with 1 if targets were not found

This commit is contained in:
Mr. Outis
2019-08-06 21:10:48 -05:00
parent 21a2d3c6ff
commit d4ef110794
4 changed files with 26 additions and 19 deletions
+19
View File
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
import argparse
import logging
import itertools
from dvc.exceptions import DvcException
from dvc.command.base import CmdBase, fix_subparsers, append_doc_link
@@ -46,6 +47,24 @@ class CmdMetricsShow(CmdBase):
)
show_metrics(metrics, self.args.all_branches, self.args.all_tags)
found = set(
itertools.chain.from_iterable(
metric.keys() for metric in metrics.values()
)
)
missing = set(self.args.targets) - found
if missing:
logger.error(
"the following metrics do not exists, "
"are not metric files or are malformed: {paths}".format(
paths=", ".join("'{}'".format(x) for x in missing)
)
)
return 1
except DvcException:
logger.exception("failed to show metrics")
return 1
-10
View File
@@ -195,16 +195,6 @@ class ReproductionError(DvcException):
super(ReproductionError, self).__init__(msg, cause=ex)
class BadMetricError(DvcException):
def __init__(self, paths):
super(BadMetricError, self).__init__(
"the following outputs do not exist, are not a metric file "
"or are malformed: {paths}".format(
paths=", ".join(relpath(path) for path in paths)
)
)
class NoMetricsError(DvcException):
def __init__(self):
super(NoMetricsError, self).__init__(
+2 -4
View File
@@ -8,7 +8,7 @@ import logging
from jsonpath_ng.ext import parse
from dvc.exceptions import OutputNotFoundError, BadMetricError, NoMetricsError
from dvc.exceptions import OutputNotFoundError, NoMetricsError
from dvc.utils.compat import builtin_str, open, StringIO, csv_reader
NO_METRICS_FILE_AT_REFERENCE_WARNING = (
@@ -282,9 +282,7 @@ def show(
if metrics:
res[branch] = metrics
if not res:
if targets:
raise BadMetricError(targets)
if not res and not targets:
raise NoMetricsError()
return res
+5 -5
View File
@@ -7,7 +7,7 @@ import logging
from dvc.repo import Repo as DvcRepo
from dvc.main import main
from dvc.exceptions import DvcException, BadMetricError, NoMetricsError
from dvc.exceptions import DvcException, NoMetricsError
from dvc.repo.metrics.show import NO_METRICS_FILE_AT_REFERENCE_WARNING
from dvc.stage import Stage
from dvc.utils import relpath
@@ -412,10 +412,10 @@ class TestMetricsRecursive(TestDvcGit):
self.dvc.scm.checkout("master")
def test(self):
with self.assertRaises(BadMetricError):
self.dvc.metrics.show(
["nested"], all_branches=True, recursive=False
)
ret = self.dvc.metrics.show(
["nested"], all_branches=True, recursive=False
)
self.assertEqual(len(ret), 0)
ret = self.dvc.metrics.show(
["nested"], all_branches=True, recursive=True