diff --git a/dvc/cli.py b/dvc/cli.py index 54ada8350..4d4cf04bd 100644 --- a/dvc/cli.py +++ b/dvc/cli.py @@ -96,11 +96,18 @@ def parse_args(argv=None): run_parser.add_argument('-d', '--deps', action='append', + default = [], help='Declare dependencies for reproducible cmd.') run_parser.add_argument('-o', '--out', action='append', - help='Declare output data items for reproducible cmd.') + default=[], + help='Declare output data file (sync to cloud) for reproducible cmd.') + run_parser.add_argument('-r', + '--reg', + action='append', + default=[], + help='Declare output regular file (sync to Git) for reproducible cmd.') run_parser.add_argument('-l', '--lock', action='store_true', diff --git a/dvc/command/add.py b/dvc/command/add.py index 945292b31..4f321cc41 100644 --- a/dvc/command/add.py +++ b/dvc/command/add.py @@ -40,7 +40,7 @@ class CmdAdd(CmdBase): for data_item in targets: Logger.debug('Creating state file for {}'.format(data_item.data.relative)) - command = CommandFile(None, [data_item.data.dvc], [], True, None) + command = CommandFile(None, [data_item.data.dvc], [], [], True, None) state_file = StateFile(data_item, self.settings, command.dict, diff --git a/dvc/command/run.py b/dvc/command/run.py index 7e9a750d2..c4e84db08 100644 --- a/dvc/command/run.py +++ b/dvc/command/run.py @@ -1,14 +1,9 @@ -import os -import sys import yaml from dvc.command.common.base import CmdBase from dvc.exceptions import DvcException -from dvc.git_wrapper import GitWrapper from dvc.logger import Logger -from dvc.repository_change import RepositoryChange from dvc.state_file import StateFile -from dvc.utils import cached_property from dvc.executor import Executor from dvc.state_file import StateFileBase @@ -24,12 +19,14 @@ class CommandFile(StateFileBase): PARAM_CMD = 'cmd' PARAM_OUT = 'out' + PARAM_REG = 'reg' PARAM_DEPS = 'deps' PARAM_LOCK = 'locked' - def __init__(self, cmd, out, deps, locked, fname): + def __init__(self, cmd, out, reg, deps, locked, fname): self.cmd = cmd self.out = out + self.reg = reg self.deps = deps self.locked = locked self.fname = fname @@ -39,6 +36,7 @@ class CommandFile(StateFileBase): data = { self.PARAM_CMD: self.cmd, self.PARAM_OUT: self.out, + self.PARAM_REG: self.reg, self.PARAM_DEPS: self.deps, self.PARAM_LOCK: self.locked } @@ -56,6 +54,7 @@ class CommandFile(StateFileBase): def loadd(data, fname=None): return CommandFile(data.get(CommandFile.PARAM_CMD, None), data.get(CommandFile.PARAM_OUT, None), + data.get(CommandFile.PARAM_REG, None), data.get(CommandFile.PARAM_DEPS, None), data.get(CommandFile.PARAM_LOCK, None), fname) @@ -75,7 +74,8 @@ class CmdRun(CmdBase): command = CommandFile.load(cmd) except Exception as exc: Logger.debug("Failed to load {}: {}".format(cmd, str(exc))) - command = CommandFile(cmd, self.parsed_args.out, self.parsed_args.deps, self.parsed_args.lock, None) + command = CommandFile(cmd, self.parsed_args.out, self.parsed_args.reg, + self.parsed_args.deps, self.parsed_args.lock, None) self.run_command(self.settings, command) return self.commit_if_needed('DVC run: {}'.format(command.cmd)) @@ -84,20 +84,24 @@ class CmdRun(CmdBase): def run_command(settings, command): Executor.exec_cmd_only_success(command.cmd, shell=True) - result = [] - items = settings.path_factory.to_data_items(command.out)[0] - for data_item in items: - Logger.debug('Move output file "{}" to cache dir "{}" and create a hardlink'.format( - data_item.data.relative, data_item.cache_dir_abs)) - data_item.move_data_to_cache() + map(lambda i: CmdRun._create_cache_and_state_files(i, command, settings), + settings.path_factory.to_data_items(command.out)[0]) + map(lambda i: CmdRun._create_state_file(i, command, settings), + settings.path_factory.to_data_items(command.reg)[0]) - Logger.debug('Create state file "{}"'.format(data_item.state.relative)) + @staticmethod + def _create_cache_and_state_files(data_item, command, settings): + Logger.debug('Move output file "{}" to cache dir "{}" and create a hardlink'.format( + data_item.data.relative, data_item.cache_dir_abs)) + data_item.move_data_to_cache() + return CmdRun._create_state_file(data_item, command, settings) - state_file = StateFile(data_item, - settings, - command.fname if command.fname else command.dict, - StateFile.parse_deps_state(settings, command.deps)) - state_file.save() - result.append(state_file) - - return result + @staticmethod + def _create_state_file(data_item, command, settings): + Logger.debug('Create state file "{}"'.format(data_item.state.relative)) + state_file = StateFile(data_item, + settings, + command.fname if command.fname else command.dict, + StateFile.parse_deps_state(settings, command.deps)) + state_file.save() + return state_file