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
5 changes: 2 additions & 3 deletions dvc/command/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,15 @@ def add_parser(subparsers, parent_parser):
"--metrics",
action="append",
default=[],
help="Declare output metric file or directory.",
help="Declare output metric file.",
metavar="<path>",
)
run_parser.add_argument(
"-M",
"--metrics-no-cache",
action="append",
default=[],
help="Declare output metric file or directory "
"(do not put into DVC cache).",
help="Declare output metric file (do not put into DVC cache).",
metavar="<path>",
)
run_parser.add_argument(
Expand Down
5 changes: 3 additions & 2 deletions dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ def save(self):

self.ignore()

if self.metric or self.plot:
self.verify_metric()

if not self.use_cache:
self.info = self.save_info()
if self.metric or self.plot:
self.verify_metric()
if not self.IS_DEPENDENCY:
logger.debug(
"Output '%s' doesn't use cache. Skipping saving.", self
Expand Down
2 changes: 1 addition & 1 deletion dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def verify_metric(self):
name = "metrics" if self.metric else "plot"
if os.path.isdir(path):
msg = "directory '{}' cannot be used as {}."
raise DvcException(msg.format(self.path_info, name))
raise IsADirectoryError(msg.format(self.path_info, name))

if not istextfile(path):
msg = "binary file '{}' cannot be used as {}."
Expand Down
28 changes: 28 additions & 0 deletions tests/func/test_run_single_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,3 +989,31 @@ def test_should_raise_on_stage_output(tmp_dir, dvc, run_copy):

with pytest.raises(OutputIsStageFileError):
run_copy("foo", "name.dvc", single_stage=True)


class TestRunDirMetrics:
@pytest.fixture(autouse=True)
def setup(self, dvc):
with open("script.py", "w+") as fobj:
fobj.write("import sys\n")
fobj.write("import os\n")
fobj.write("os.makedirs(sys.argv[1])\n")
fobj.write(
"with open(os.path.join(sys.argv[1], "
"'metrics.json'), 'a+') as fobj:\n"
)
fobj.write(" fobj.write('foo')\n")

def test_metrics_dir_cached(self, dvc):
with pytest.raises(IsADirectoryError):
dvc.run(
cmd="python script.py dir", metrics=["dir"], single_stage=True,
)

def test_metrics_dir_not_cached(self, dvc):
with pytest.raises(IsADirectoryError):
dvc.run(
cmd="python script.py dir",
metrics_no_cache=["dir"],
single_stage=True,
)