Refactoring: extract method _reproduce_stages() and ReproductionError class changes

This commit is contained in:
Dmitry
2018-01-10 09:57:22 -08:00
parent f11183446e
commit 8cc3887769
+14 -9
View File
@@ -28,6 +28,8 @@ class StageNotFoundError(DvcException):
class ReproductionError(DvcException):
def __init__(self, dvc_file_name, msg):
self.dvc_file_name = dvc_file_name
self.msg = msg
super(ReproductionError, self).__init__(u'Failed to reproduce \'{}\': {}'.format(dvc_file_name, msg))
@@ -173,20 +175,12 @@ class Project(object):
return stage
def reproduce(self, target, recursive=True, force=False):
reproduced = []
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)
if recursive:
for n in nx.dfs_postorder_nodes(self.graph(), node):
try:
stages[n].reproduce(force=force)
stages[n].dump()
reproduced.append(stages[n])
except Exception as ex:
raise ReproductionError(n, ex.message)
reproduced = self._reproduce_stages(force, node, stages) if recursive else []
stages[node].reproduce(force=force)
stages[node].dump()
@@ -194,6 +188,17 @@ class Project(object):
return reproduced
def _reproduce_stages(self, force, node, stages):
result = []
for n in nx.dfs_postorder_nodes(self.graph(), node):
try:
stages[n].reproduce(force=force)
stages[n].dump()
result.append(stages[n])
except Exception as ex:
raise ReproductionError(n, ex.message)
return result
def checkout(self):
for stage in self.stages():
stage.checkout()