Make the graph '_unsatisfied_requires' be a staticmethod

To make it possible for users to subclass this flow and
replace this method (if they so choose to) make it a static
method that is directed to the current module level function
and call into the staticmethod when used (users can override
staticmethods and change them in subclasses).

Change-Id: I747c45636596ca5a8ad81dabcbba12ab55ce77d7
This commit is contained in:
Joshua Harlow
2015-03-25 17:00:54 -07:00
parent c85805fca1
commit 977d19caa3

View File

@@ -22,7 +22,6 @@ from taskflow.types import graph as gr
def _unsatisfied_requires(node, graph, *additional_provided):
"""Extracts the unsatisified symbol requirements of a single node."""
requires = set(node.requires)
if not requires:
return requires
@@ -64,6 +63,9 @@ class Flow(flow.Flow):
self._graph = gr.DiGraph()
self._graph.freeze()
#: Extracts the unsatisified symbol requirements of a single node.
_unsatisfied_requires = staticmethod(_unsatisfied_requires)
def link(self, u, v):
"""Link existing node u as a runtime dependency of existing node v."""
if not self._graph.has_node(u):
@@ -153,7 +155,7 @@ class Flow(flow.Flow):
provided[value].append(self._retry)
for item in self._graph.nodes_iter():
for value in _unsatisfied_requires(item, self._graph,
for value in self._unsatisfied_requires(item, self._graph,
retry_provides):
required[value].append(item)
for value in item.provides:
@@ -168,7 +170,7 @@ class Flow(flow.Flow):
# Try to find a valid provider.
if resolve_requires:
for value in _unsatisfied_requires(item, tmp_graph,
for value in self._unsatisfied_requires(item, tmp_graph,
retry_provides):
if value in provided:
providers = provided[value]
@@ -232,7 +234,8 @@ class Flow(flow.Flow):
retry_provides.update(self._retry.provides)
g = self._get_subgraph()
for item in g.nodes_iter():
requires.update(_unsatisfied_requires(item, g, retry_provides))
requires.update(self._unsatisfied_requires(item, g,
retry_provides))
return frozenset(requires)