repro: don't reproduce twice

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-01-18 19:49:08 +02:00
parent b67e74f977
commit 2b8c8b62f0
2 changed files with 19 additions and 13 deletions
+13 -10
View File
@@ -170,27 +170,30 @@ class Project(object):
stage.dump()
return stage
def _reproduce_stage(self, stages, node, force):
if not stages[node].changed():
return []
stages[node].reproduce(force=force)
stages[node].dump()
return [stages[node]]
def reproduce(self, target, recursive=True, force=False):
stages = nx.get_node_attributes(self.graph(), 'stage')
node = os.path.relpath(os.path.abspath(target), self.root_dir)
if node not in stages:
raise StageNotFoundError(target)
reproduced = self._reproduce_stages(force, node, stages) if recursive else []
if recursive:
return self._reproduce_stages(stages, node, force)
stages[node].reproduce(force=force)
stages[node].dump()
reproduced.append(stages[node])
return self._reproduce_stage(stages, node, force)
return reproduced
def _reproduce_stages(self, force, node, stages):
def _reproduce_stages(self, stages, node, force):
result = []
for n in nx.dfs_postorder_nodes(self.graph(), node):
try:
stages[n].reproduce(force=force)
stages[n].dump()
result.append(stages[n])
result += self._reproduce_stage(stages, n, force)
except Exception as ex:
raise ReproductionError(n, str(ex))
return result
+6 -3
View File
@@ -31,18 +31,20 @@ class TestReproChangedCode(TestRepro):
with open(self.CODE, 'a') as code:
code.write("\nshutil.copyfile('{}', sys.argv[2])\n".format(self.BAR))
self.dvc.reproduce(self.file1_stage)
stages = self.dvc.reproduce(self.file1_stage)
self.assertTrue(filecmp.cmp(self.file1, self.BAR))
self.assertEqual(len(stages), 1)
class TestReproChangedData(TestRepro):
def test(self):
self.swap_foo_with_bar()
self.dvc.reproduce(self.file1_stage)
stages = self.dvc.reproduce(self.file1_stage)
self.assertTrue(filecmp.cmp(self.file1, self.BAR))
self.assertEqual(len(stages), 2)
def swap_foo_with_bar(self):
os.chmod(self.FOO, stat.S_IWRITE)
@@ -61,10 +63,11 @@ class TestReproChangedDeepData(TestReproChangedData):
self.swap_foo_with_bar()
self.dvc.reproduce(file2_stage)
stages = self.dvc.reproduce(file2_stage)
self.assertTrue(filecmp.cmp(self.file1, self.BAR))
self.assertTrue(filecmp.cmp(file2, self.BAR))
self.assertEqual(len(stages), 3)
class TestReproPhony(TestReproChangedData):