mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-08 15:28:26 +01:00
run: add --no-exec option
Fixes #385 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -113,6 +113,11 @@ def parse_args(argv=None):
|
||||
'--cwd',
|
||||
default=os.path.curdir,
|
||||
help='Directory to run your command and place state file in')
|
||||
run_parser.add_argument(
|
||||
'--no-exec',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Only create stage file without actually running it")
|
||||
run_parser.add_argument(
|
||||
'command',
|
||||
nargs=argparse.REMAINDER,
|
||||
|
||||
+14
-7
@@ -3,19 +3,26 @@ import os
|
||||
from dvc.command.common.base import CmdBase
|
||||
from dvc.logger import Logger
|
||||
from dvc.stage import Stage
|
||||
from dvc.exceptions import DvcException
|
||||
|
||||
|
||||
class CmdRun(CmdBase):
|
||||
def run(self):
|
||||
fname = self.stage_file_name(self.args.file, self.args.outs, self.args.outs_no_cache)
|
||||
|
||||
self.project.run(cmd=' '.join(self.args.command),
|
||||
outs=self.args.outs,
|
||||
outs_no_cache=self.args.outs_no_cache,
|
||||
deps=self.args.deps,
|
||||
locked=self.args.lock,
|
||||
fname=fname,
|
||||
cwd=self.args.cwd)
|
||||
try:
|
||||
self.project.run(cmd=' '.join(self.args.command),
|
||||
outs=self.args.outs,
|
||||
outs_no_cache=self.args.outs_no_cache,
|
||||
deps=self.args.deps,
|
||||
locked=self.args.lock,
|
||||
fname=fname,
|
||||
cwd=self.args.cwd,
|
||||
no_exec=self.args.no_exec)
|
||||
except DvcException as ex:
|
||||
self.project.logger.error('Failed to run command: {}'.format(str(ex)))
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
|
||||
+4
-2
@@ -145,7 +145,8 @@ class Project(object):
|
||||
outs_no_cache=[],
|
||||
locked=False,
|
||||
fname=Stage.STAGE_FILE,
|
||||
cwd=os.curdir):
|
||||
cwd=os.curdir,
|
||||
no_exec=False):
|
||||
cwd = os.path.abspath(cwd)
|
||||
path = os.path.join(cwd, fname)
|
||||
outputs = Output.loads_from(self, outs, use_cache=True, cwd=cwd)
|
||||
@@ -159,7 +160,8 @@ class Project(object):
|
||||
outs=outputs,
|
||||
deps=deps,
|
||||
locked=locked)
|
||||
stage.run()
|
||||
if not no_exec:
|
||||
stage.run()
|
||||
stage.dump()
|
||||
return stage
|
||||
|
||||
|
||||
@@ -45,3 +45,10 @@ class TestRunEmpty(TestDvc):
|
||||
locked=False,
|
||||
fname='empty.dvc',
|
||||
cwd=os.curdir)
|
||||
|
||||
|
||||
class TestRunNoExec(TestDvc):
|
||||
def test(self):
|
||||
self.dvc.run(cmd='python {} {} {}'.format(self.CODE, self.FOO, 'out'),
|
||||
no_exec=True)
|
||||
self.assertFalse(os.path.exists('out'))
|
||||
|
||||
Reference in New Issue
Block a user