Merge pull request #337 from dataversioncontrol/git_file_state_file_fix

Git file output fix
This commit is contained in:
Dmitry Petrov
2017-12-06 00:56:13 -08:00
committed by GitHub
4 changed files with 31 additions and 29 deletions
+27 -19
View File
@@ -1,6 +1,7 @@
import os
from dvc.command.common.base import CmdBase
from dvc.data_cloud import file_md5
from dvc.exceptions import DvcException
from dvc.logger import Logger
from dvc.state_file import StateFile
@@ -18,7 +19,7 @@ class CmdRun(CmdBase):
def run(self):
cmd = ' '.join(self.parsed_args.command)
command = StateFile(data_item=None,
state = StateFile(data_item=None,
cmd=cmd,
out=self.parsed_args.out,
out_git=self.parsed_args.out_git,
@@ -26,36 +27,43 @@ class CmdRun(CmdBase):
locked=self.parsed_args.lock,
md5=None)
self.run_command(self.settings, command)
return self.commit_if_needed('DVC run: {}'.format(command.cmd))
self.run_command(self.settings, state)
return self.commit_if_needed('DVC run: {}'.format(state.cmd))
@staticmethod
def run_command(settings, command):
Executor.exec_cmd_only_success(command.cmd, shell=True)
def run_command(settings, state):
Executor.exec_cmd_only_success(state.cmd, shell=True)
CmdRun.apply_to_files(command.out, command, CmdRun._create_cache_and_state_files, settings)
CmdRun.apply_to_files(command.out_git, command, CmdRun._create_state_file, settings)
CmdRun.apply_to_files(state.out, state, CmdRun._create_cache_and_state_files, settings)
CmdRun.apply_to_files(state.out_git, state, CmdRun._create_state_file, settings)
@staticmethod
def apply_to_files(files, command, func, settings):
[func(i, command, settings) for i in settings.path_factory.to_data_items(files)[0]]
def apply_to_files(files, state, func, settings):
items = settings.path_factory.to_data_items(files)[0]
[func(i, state, settings) for i in items]
@staticmethod
def _create_cache_and_state_files(data_item, command, settings):
def _create_cache_and_state_files(data_item, state, 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)
return CmdRun._create_state_file(data_item, state, settings, cache_file_exists = True)
@staticmethod
def _create_state_file(data_item, command, settings):
def _create_state_file(data_item, state, settings, cache_file_exists=False):
Logger.debug('Create state file "{}"'.format(data_item.state.relative))
state_file = StateFile(data_item=data_item,
cmd=command.cmd,
out=command.out,
out_git=command.out_git,
locked=command.locked,
deps=StateFile.parse_deps_state(settings, command.deps),
md5=os.path.basename(data_item.cache.relative))
if cache_file_exists:
md5 = os.path.basename(data_item.cache.relative)
else:
md5 = file_md5(data_item.data.relative)[0]
state_file = StateFile(data_item,
state.cmd,
state.out,
state.out_git,
locked=state.locked,
deps=StateFile.parse_deps_state(settings, state.deps),
md5=md5)
state_file.save()
return state_file
+2 -3
View File
@@ -5,10 +5,9 @@ from collections import defaultdict
from dvc import utils
from dvc.exceptions import DvcException
from dvc.logger import Logger
from dvc.config import Config, ConfigI
from dvc.config import Config
from dvc.executor import Executor, ExecutorError
from dvc.path.data_item import DataItemError
from dvc.state_file import StateFile
from dvc.path.data_item import DataItem
from dvc.system import System
from dvc.graph.workflow import Workflow
from dvc.graph.commit import Commit
+1 -1
View File
@@ -23,7 +23,7 @@ class DataDirError(DvcException):
class DataItemInConfigDirError(DataDirError):
def __init__(self, file):
msg = 'File "{}" is in config directory'.format(file)
super(DataItemInStatusDirError, self).__init__(msg)
super(DataDirError, self).__init__(msg)
class NotInGitDirError(DataDirError):
+1 -6
View File
@@ -1,14 +1,10 @@
import os
import ntpath
import sys
import yaml
import re
from dvc import utils
from dvc.exceptions import DvcException
from dvc.system import System
from dvc.data_cloud import file_md5
class StateFileError(DvcException):
def __init__(self, msg):
DvcException.__init__(self, 'State file error: {}'.format(msg))
@@ -48,7 +44,6 @@ class StateFile(StateFileBase):
locked=None,
md5=None):
super(StateFile, self).__init__()
self.data_item = data_item
self.cmd = cmd