mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 15:28:28 +01:00
run: introduce --overwrite-dvcfile and --ignore-build-cache
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+8
-1
@@ -273,11 +273,18 @@ def parse_args(argv=None):
|
||||
"when '.dvc' file exists and dvc asks if you "
|
||||
"want to overwrite it.")
|
||||
run_parser.add_argument(
|
||||
'--force',
|
||||
'--overwrite-dvcfile',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Overwrite existing dvc file without asking "
|
||||
"for confirmation.")
|
||||
run_parser.add_argument(
|
||||
'--ignore-build-cache',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Run this stage even if it has been already "
|
||||
"ran with the same command/dependencies/outputs/etc "
|
||||
"before.")
|
||||
run_parser.add_argument(
|
||||
'command',
|
||||
nargs=argparse.REMAINDER,
|
||||
|
||||
+3
-1
@@ -20,6 +20,7 @@ class CmdRun(CmdBase):
|
||||
return cmd
|
||||
|
||||
def run(self):
|
||||
overwrite = (self.args.yes or self.args.overwrite_dvcfile)
|
||||
try:
|
||||
self.project.run(cmd=self._joined_cmd(),
|
||||
outs=self.args.outs,
|
||||
@@ -29,7 +30,8 @@ class CmdRun(CmdBase):
|
||||
fname=self.args.file,
|
||||
cwd=self.args.cwd,
|
||||
no_exec=self.args.no_exec,
|
||||
overwrite=(self.args.yes or self.args.force))
|
||||
overwrite=overwrite,
|
||||
ignore_build_cache=self.args.ignore_build_cache)
|
||||
except DvcException as ex:
|
||||
self.project.logger.error('Failed to run command', ex)
|
||||
return 1
|
||||
|
||||
+4
-2
@@ -363,7 +363,8 @@ class Project(object):
|
||||
fname=None,
|
||||
cwd=os.curdir,
|
||||
no_exec=False,
|
||||
overwrite=False):
|
||||
overwrite=False,
|
||||
ignore_build_cache=False):
|
||||
from dvc.stage import Stage
|
||||
|
||||
with self.state:
|
||||
@@ -375,7 +376,8 @@ class Project(object):
|
||||
outs_no_cache=outs_no_cache,
|
||||
metrics_no_cache=metrics_no_cache,
|
||||
deps=deps,
|
||||
overwrite=overwrite)
|
||||
overwrite=overwrite,
|
||||
ignore_build_cache=ignore_build_cache)
|
||||
|
||||
if stage is None:
|
||||
return None
|
||||
|
||||
+7
-6
@@ -339,7 +339,8 @@ class Stage(object):
|
||||
cwd=os.curdir,
|
||||
locked=False,
|
||||
add=False,
|
||||
overwrite=True):
|
||||
overwrite=True,
|
||||
ignore_build_cache=False):
|
||||
|
||||
stage = Stage(project=project,
|
||||
cwd=cwd,
|
||||
@@ -367,14 +368,14 @@ class Stage(object):
|
||||
stage.cwd = cwd
|
||||
stage.path = path
|
||||
|
||||
if os.path.exists(path) and not overwrite:
|
||||
if stage.is_cached():
|
||||
if os.path.exists(path):
|
||||
if not ignore_build_cache and stage.is_cached():
|
||||
Logger.info('Stage is cached, skipping.')
|
||||
return None
|
||||
|
||||
msg = "'{}' already exists. " \
|
||||
"Do you wish to run the command and overwrite it?"
|
||||
if not project.prompt.prompt(msg.format(stage.relpath), False):
|
||||
msg = "'{}' already exists. Do you wish to run the command and " \
|
||||
"overwrite it?".format(stage.relpath)
|
||||
if not overwrite and not project.prompt.prompt(msg, False):
|
||||
raise StageFileAlreadyExistsError(stage.relpath)
|
||||
|
||||
return stage
|
||||
|
||||
+43
-1
@@ -195,12 +195,51 @@ class TestCmdRunOverwrite(TestDvc):
|
||||
'python', self.CODE, self.FOO, 'out'])
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
stage_mtime = os.path.getmtime('out.dvc')
|
||||
out_mtime = os.path.getmtime('out')
|
||||
|
||||
ret = main(['run',
|
||||
'--force',
|
||||
'-d', self.FOO,
|
||||
'-d', self.CODE,
|
||||
'-o', 'out',
|
||||
'-f', 'out.dvc',
|
||||
'python', self.CODE, self.FOO, 'out'])
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
# NOTE: check output and dvcfile were NOT overwritten
|
||||
self.assertEqual(stage_mtime, os.path.getmtime('out.dvc'))
|
||||
self.assertEqual(out_mtime, os.path.getmtime('out'))
|
||||
|
||||
stage_mtime = os.path.getmtime('out.dvc')
|
||||
out_mtime = os.path.getmtime('out')
|
||||
|
||||
ret = main(['run',
|
||||
'-d', self.FOO,
|
||||
'-d', self.CODE,
|
||||
'--overwrite-dvcfile',
|
||||
'--ignore-build-cache',
|
||||
'-o', 'out',
|
||||
'-f', 'out.dvc',
|
||||
'python', self.CODE, self.FOO, 'out'])
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
# NOTE: check output and dvcfile were overwritten
|
||||
self.assertNotEqual(stage_mtime, os.path.getmtime('out.dvc'))
|
||||
self.assertNotEqual(out_mtime, os.path.getmtime('out'))
|
||||
|
||||
stage_mtime = os.path.getmtime('out.dvc')
|
||||
out_mtime = os.path.getmtime('out')
|
||||
|
||||
ret = main(['run',
|
||||
'--overwrite-dvcfile',
|
||||
'-f', 'out.dvc',
|
||||
'-d', self.BAR])
|
||||
self.assertEqual(ret, 0)
|
||||
|
||||
# NOTE: check output was NOT overwritten, but dvcfile was
|
||||
self.assertEqual(out_mtime, os.path.getmtime('out'))
|
||||
self.assertNotEqual(stage_mtime, os.path.getmtime('out.dvc'))
|
||||
|
||||
|
||||
class TestRunDeterministicBase(TestDvc):
|
||||
def setUp(self):
|
||||
@@ -211,6 +250,7 @@ class TestRunDeterministicBase(TestDvc):
|
||||
self.deps = [self.FOO, self.CODE]
|
||||
self.outs = [self.out_file]
|
||||
self.overwrite = False
|
||||
self.ignore_build_cache = False
|
||||
|
||||
self._run()
|
||||
|
||||
@@ -218,6 +258,7 @@ class TestRunDeterministicBase(TestDvc):
|
||||
self.stage = self.dvc.run(cmd=self.cmd,
|
||||
fname=self.stage_file,
|
||||
overwrite=self.overwrite,
|
||||
ignore_build_cache=self.ignore_build_cache,
|
||||
deps=self.deps,
|
||||
outs=self.outs)
|
||||
|
||||
@@ -230,6 +271,7 @@ class TestRunDeterministic(TestRunDeterministicBase):
|
||||
class TestRunDeterministicOverwrite(TestRunDeterministicBase):
|
||||
def test(self):
|
||||
self.overwrite = True
|
||||
self.ignore_build_cache = True
|
||||
self._run()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user