From 977d19caa3a632e1cd4ed133b35d7ef274fc05d3 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 25 Mar 2015 17:00:54 -0700 Subject: [PATCH] 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 --- taskflow/patterns/graph_flow.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/taskflow/patterns/graph_flow.py b/taskflow/patterns/graph_flow.py index d36a72ff..bb779cb2 100644 --- a/taskflow/patterns/graph_flow.py +++ b/taskflow/patterns/graph_flow.py @@ -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,8 +155,8 @@ class Flow(flow.Flow): provided[value].append(self._retry) for item in self._graph.nodes_iter(): - for value in _unsatisfied_requires(item, self._graph, - retry_provides): + for value in self._unsatisfied_requires(item, self._graph, + retry_provides): required[value].append(item) for value in item.provides: provided[value].append(item) @@ -168,8 +170,8 @@ class Flow(flow.Flow): # Try to find a valid provider. if resolve_requires: - for value in _unsatisfied_requires(item, tmp_graph, - retry_provides): + for value in self._unsatisfied_requires(item, tmp_graph, + retry_provides): if value in provided: providers = provided[value] if len(providers) > 1: @@ -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)