From e81c6f2b34a0b74dee2d58fa8ba9c37240446cc0 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 3 Dec 2018 05:13:54 +0200 Subject: [PATCH] run: introduce --force option Signed-off-by: Ruslan Kuprieiev --- dvc/cli.py | 9 ++++++++- dvc/command/run.py | 6 ++---- tests/test_run.py | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/dvc/cli.py b/dvc/cli.py index 4f3ceb90b..4d218b2a8 100644 --- a/dvc/cli.py +++ b/dvc/cli.py @@ -268,9 +268,16 @@ def parse_args(argv=None): '--yes', action='store_true', default=False, - help="Automatic 'yes' answer to all prompts. E.g. " + help="(OBSOLETED, use --force instead) Automatic " + "'yes' answer to all prompts. E.g. " "when '.dvc' file exists and dvc asks if you " "want to overwrite it.") + run_parser.add_argument( + '--force', + action='store_true', + default=False, + help="Overwrite existing dvc file without asking " + "for confirmation.") run_parser.add_argument( 'command', nargs=argparse.REMAINDER, diff --git a/dvc/command/run.py b/dvc/command/run.py index 0fa2c2036..b6559e8f3 100644 --- a/dvc/command/run.py +++ b/dvc/command/run.py @@ -21,9 +21,6 @@ class CmdRun(CmdBase): def run(self): try: - if self.args.yes: - self.project.prompt.default = True - self.project.run(cmd=self._joined_cmd(), outs=self.args.outs, outs_no_cache=self.args.outs_no_cache, @@ -31,7 +28,8 @@ class CmdRun(CmdBase): deps=self.args.deps, fname=self.args.file, cwd=self.args.cwd, - no_exec=self.args.no_exec) + no_exec=self.args.no_exec, + overwrite=(self.args.yes or self.args.force)) except DvcException as ex: self.project.logger.error('Failed to run command', ex) return 1 diff --git a/tests/test_run.py b/tests/test_run.py index 5f7ee848f..bf5a3e229 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -185,6 +185,23 @@ class TestCmdRun(TestDvc): self.assertEqual(ret, 252) +class TestCmdRunOverwrite(TestDvc): + def test(self): + ret = main(['run', + '-d', self.FOO, + '-d', self.CODE, + '-o', 'out', + '-f', 'out.dvc', + 'python', self.CODE, self.FOO, 'out']) + self.assertEqual(ret, 0) + + ret = main(['run', + '--force', + '-f', 'out.dvc', + '-d', self.BAR]) + self.assertEqual(ret, 0) + + class TestRunDeterministicBase(TestDvc): def setUp(self): super(TestRunDeterministicBase, self).setUp()