mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Refactoring: extract method _reproduce_stages() and ReproductionError class changes
This commit is contained in:
+14
-9
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user