Skip to content

Commit

Permalink
Merge pull request iterative#576 from efiop/master
Browse files Browse the repository at this point in the history
dvc: fix checkout/repro with stage files without md5
  • Loading branch information
efiop authored Mar 19, 2018
2 parents 69b5ec7 + 958eab2 commit a46e4ea
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
12 changes: 9 additions & 3 deletions dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,16 @@ def __init__(self, project, path, md5=None, use_cache=True):

@property
def cache(self):
if not self.md5:
return None

return self.project.cache.get(self.md5)

@property
def rel_cache(self):
if not self.cache:
return None

return os.path.relpath(self.cache)

def dumpd(self, cwd):
Expand Down Expand Up @@ -198,10 +204,10 @@ def dir_info_dict(dir_info):
return {i['relpath']: i['md5'] for i in dir_info}

def changed(self):
ret = True

if not self.use_cache:
ret = super(Output, self).changed()
elif not self.cache:
ret = True
elif self.is_dir_cache(self.cache):
ret = self._changed_dir()
else:
Expand Down Expand Up @@ -280,7 +286,7 @@ def checkout(self):
self.project.logger.debug(msg.format(self.rel_path, self.rel_cache))
return

if not os.path.exists(self.cache):
if not self.cache or not os.path.exists(self.cache):
self.project.logger.warn(u'\'{}\': cache file not found'.format(self.rel_path))
self.remove()
return
Expand Down
2 changes: 1 addition & 1 deletion dvc/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _used_cache(self, target=None):

for stage in stages:
for out in stage.outs:
if not out.use_cache:
if not out.use_cache or not out.cache:
continue
cache_set |= set([out.cache])
if out.is_dir_cache(out.cache) and os.path.isfile(out.cache):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_checkout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import yaml
import time
import stat
import shutil
Expand All @@ -7,6 +8,8 @@
from dvc.main import main
from tests.basic_env import TestDvc
from tests.test_repro import TestRepro
from dvc.stage import Stage
from dvc.output import Output


class TestCheckout(TestRepro):
Expand Down Expand Up @@ -146,3 +149,17 @@ def test(self):
main(['checkout'])
ignored = self.read_ignored()
self.assertIn(fname_branch, ignored)


class TestCheckoutMissingMd5InStageFile(TestRepro):
def test(self):
with open(self.file1_stage, 'r') as fd:
d = yaml.load(fd)

del(d[Stage.PARAM_OUTS][0][Output.PARAM_MD5])
del(d[Stage.PARAM_DEPS][0][Output.PARAM_MD5])

with open(self.file1_stage, 'w') as fd:
yaml.dump(d, fd)

self.dvc.checkout()
18 changes: 18 additions & 0 deletions tests/test_repro.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import yaml
import stat
import shutil
import filecmp
Expand All @@ -7,6 +8,8 @@
from dvc.command.repro import CmdRepro
from dvc.project import ReproductionError
from dvc.utils import file_md5
from dvc.output import Output
from dvc.stage import Stage

from tests.basic_env import TestDvc

Expand Down Expand Up @@ -135,6 +138,21 @@ def test(self):
self.assertEqual(len(stages), 1)


class TestReproMissingMd5InStageFile(TestRepro):
def test(self):
with open(self.file1_stage, 'r') as fd:
d = yaml.load(fd)

del(d[Stage.PARAM_OUTS][0][Output.PARAM_MD5])
del(d[Stage.PARAM_DEPS][0][Output.PARAM_MD5])

with open(self.file1_stage, 'w') as fd:
yaml.dump(d, fd)

stages = self.dvc.reproduce(self.file1_stage)
self.assertEqual(len(stages), 1)


class TestCmdRepro(TestRepro):
def test(self):
ret = main(['repro',
Expand Down

0 comments on commit a46e4ea

Please sign in to comment.