mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 15:28:28 +01:00
+23
-17
@@ -4,26 +4,11 @@ from dvc.exceptions import DvcException
|
||||
|
||||
|
||||
class CmdRun(CmdBase):
|
||||
def _joined_cmd(self):
|
||||
if len(self.args.command) == 0:
|
||||
return ''
|
||||
|
||||
if len(self.args.command) == 1:
|
||||
return self.args.command[0]
|
||||
|
||||
cmd = ''
|
||||
for chunk in self.args.command:
|
||||
if len(chunk.split()) != 1:
|
||||
fmt = ' "{}"'
|
||||
else:
|
||||
fmt = ' {}'
|
||||
cmd += fmt.format(chunk)
|
||||
return cmd
|
||||
|
||||
def run(self):
|
||||
overwrite = (self.args.yes or self.args.overwrite_dvcfile)
|
||||
|
||||
try:
|
||||
self.project.run(cmd=self._joined_cmd(),
|
||||
self.project.run(cmd=self._parsed_cmd(),
|
||||
outs=self.args.outs,
|
||||
outs_no_cache=self.args.outs_no_cache,
|
||||
metrics_no_cache=self.args.metrics_no_cache,
|
||||
@@ -39,3 +24,24 @@ class CmdRun(CmdBase):
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
def _parsed_cmd(self):
|
||||
"""
|
||||
We need to take into account two cases:
|
||||
|
||||
- ['python code.py foo bar']: Used mainly with dvc as a library
|
||||
- ['echo', 'foo bar']: List of arguments received from the CLI
|
||||
|
||||
The second case would need quoting, as it was passed through:
|
||||
dvc run echo "foo bar"
|
||||
"""
|
||||
if len(self.args.command) < 2:
|
||||
return ' '.join(self.args.command)
|
||||
|
||||
return ' '.join(self._quote_argument(arg) for arg in self.args.command)
|
||||
|
||||
def _quote_argument(self, argument):
|
||||
if ' ' not in argument or '"' in argument:
|
||||
return argument
|
||||
|
||||
return '"{}"'.format(argument)
|
||||
|
||||
Reference in New Issue
Block a user