mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-08 15:28:26 +01:00
dvc run: regular file output. Close #314
This commit is contained in:
+8
-1
@@ -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',
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
+26
-22
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user