mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 15:28:34 +01:00
run: introduce --remove-outs option
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -285,6 +285,11 @@ def parse_args(argv=None):
|
||||
help="Run this stage even if it has been already "
|
||||
"ran with the same command/dependencies/outputs/etc "
|
||||
"before.")
|
||||
run_parser.add_argument(
|
||||
'--remove-outs',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Remove outputs before running the command.")
|
||||
run_parser.add_argument(
|
||||
'command',
|
||||
nargs=argparse.REMAINDER,
|
||||
|
||||
+2
-1
@@ -31,7 +31,8 @@ class CmdRun(CmdBase):
|
||||
cwd=self.args.cwd,
|
||||
no_exec=self.args.no_exec,
|
||||
overwrite=overwrite,
|
||||
ignore_build_cache=self.args.ignore_build_cache)
|
||||
ignore_build_cache=self.args.ignore_build_cache,
|
||||
remove_outs=self.args.remove_outs)
|
||||
except DvcException as ex:
|
||||
self.project.logger.error('Failed to run command', ex)
|
||||
return 1
|
||||
|
||||
+4
-2
@@ -364,7 +364,8 @@ class Project(object):
|
||||
cwd=os.curdir,
|
||||
no_exec=False,
|
||||
overwrite=False,
|
||||
ignore_build_cache=False):
|
||||
ignore_build_cache=False,
|
||||
remove_outs=False):
|
||||
from dvc.stage import Stage
|
||||
|
||||
with self.state:
|
||||
@@ -377,7 +378,8 @@ class Project(object):
|
||||
metrics_no_cache=metrics_no_cache,
|
||||
deps=deps,
|
||||
overwrite=overwrite,
|
||||
ignore_build_cache=ignore_build_cache)
|
||||
ignore_build_cache=ignore_build_cache,
|
||||
remove_outs=remove_outs)
|
||||
|
||||
if stage is None:
|
||||
return None
|
||||
|
||||
+6
-1
@@ -340,7 +340,8 @@ class Stage(object):
|
||||
locked=False,
|
||||
add=False,
|
||||
overwrite=True,
|
||||
ignore_build_cache=False):
|
||||
ignore_build_cache=False,
|
||||
remove_outs=False):
|
||||
|
||||
stage = Stage(project=project,
|
||||
cwd=cwd,
|
||||
@@ -368,6 +369,10 @@ class Stage(object):
|
||||
stage.cwd = cwd
|
||||
stage.path = path
|
||||
|
||||
# NOTE: remove outs before we check build cache
|
||||
if remove_outs:
|
||||
stage.remove_outs(ignore_remove=False)
|
||||
|
||||
if os.path.exists(path):
|
||||
if not ignore_build_cache and stage.is_cached():
|
||||
Logger.info('Stage is cached, skipping.')
|
||||
|
||||
@@ -185,6 +185,23 @@ class TestCmdRun(TestDvc):
|
||||
self.assertEqual(ret, 252)
|
||||
|
||||
|
||||
class TestRunRemoveOuts(TestDvc):
|
||||
def test(self):
|
||||
with open(self.CODE, 'w+') as fobj:
|
||||
fobj.write("import sys\n")
|
||||
fobj.write("import os\n")
|
||||
fobj.write("if os.path.exists(sys.argv[1]):\n")
|
||||
fobj.write(" sys.exit(1)\n")
|
||||
fobj.write("open(sys.argv[1], 'w+').close()\n")
|
||||
|
||||
ret = main(['run',
|
||||
'--remove-outs',
|
||||
'-d', self.CODE,
|
||||
'-o', self.FOO,
|
||||
'python', self.CODE, self.FOO])
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
|
||||
class TestCmdRunOverwrite(TestDvc):
|
||||
def test(self):
|
||||
ret = main(['run',
|
||||
|
||||
Reference in New Issue
Block a user