mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
repro: don't reproduce twice
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+13
-10
@@ -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
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user