3333
3434def _node_is_destination (graph , node ):
3535 """
36- Determine whether or not the given node features
36+ Determine whether the given node features
3737 in a destination of another node. Return True if
38- the node is a destination, False otherwise..
38+ the node is a destination, False otherwise.
3939 """
4040 for graph_node in graph :
4141 if node in graph [graph_node ]:
@@ -86,7 +86,7 @@ def _determine_topological_order(graph, starting_set):
8686
8787def _reverse_dict_with_lists (in_dict ):
8888 reverseDictOut = {}
89- for k , v in list ( in_dict .items () ):
89+ for k , v in in_dict .items ():
9090 for rk in v :
9191 reverseDictOut [rk ] = reverseDictOut .get (rk , [])
9292 reverseDictOut [rk ].append (k )
@@ -98,7 +98,6 @@ class WorkflowDependencyGraph(object):
9898
9999 def __init__ (self , scene ):
100100 self ._scene = scene
101- self ._dependency_graph = {}
102101 self ._reverse_dependency_graph = {}
103102 self ._topological_order = []
104103 self ._current = - 1
@@ -122,12 +121,16 @@ def _find_all_connected_nodes(self):
122121
123122 def _calculate_dependency_graph (self ):
124123 graph = {}
125- for item in list (self ._scene .items ()):
124+ graph_ports = []
125+ for item in self ._scene .items ():
126126 if item .Type == Connection .Type :
127127 graph [item .source ()] = graph .get (item .source (), [])
128128 graph [item .source ()].append (item .destination ())
129-
130- return graph
129+ graph_ports .append (
130+ {'from' : item .source (), 'from_port' : item .sourceIndex (),
131+ 'to' : item .destination (), 'to_port' : item .destinationIndex ()}
132+ )
133+ return graph , graph_ports
131134
132135 def _solo_node (self ):
133136 scene_items = list (self ._scene .items ())
@@ -153,31 +156,36 @@ def set_finished_callback(self, callback):
153156 def execute_status_message (self ):
154157 return self ._execute_status_message
155158
156- def can_execute (self ):
157- self ._dependency_graph = self ._calculate_dependency_graph ()
158- self ._reverse_dependency_graph = _reverse_dict_with_lists (self ._dependency_graph )
159+ def graph (self ):
160+ dependency_graph , graph_ports = self ._calculate_dependency_graph ()
161+ return dependency_graph , graph_ports , _reverse_dict_with_lists (dependency_graph )
162+
163+ def _determine_graph (self ):
164+ dependency_graph , _ = self ._calculate_dependency_graph ()
165+ self ._reverse_dependency_graph = _reverse_dict_with_lists (dependency_graph )
159166 # Find all connected nodes in the graph
160167 nodes = self ._find_all_connected_nodes ()
161168 # Find starting point set, uses helper graph
162- starting_set = _find_starting_set (self . _dependency_graph , nodes )
169+ starting_set = _find_starting_set (dependency_graph , nodes )
163170
164- self ._topological_order = _determine_topological_order (self . _dependency_graph , starting_set )
171+ self ._topological_order = _determine_topological_order (dependency_graph , starting_set )
165172
166- items_count = len (self ._scene .items ())
167173 solo_node = self ._solo_node ()
168174 if solo_node :
169- self ._dependency_graph = {solo_node : []}
170175 self ._topological_order = [solo_node ]
171176
177+ def can_execute (self ):
178+ self ._determine_graph ()
172179 configured = [metastep .getStep ().isConfigured () for metastep in self ._topological_order ]
173180
181+ items_count = len (self ._scene .items ())
174182 if not all (configured ):
175183 self ._execute_status_message = "Not all steps are configured."
176184 return 1
177185 elif items_count == 0 :
178186 self ._execute_status_message = "No steps in workflow."
179187 return 2
180- elif items_count > 1 and len (self ._topological_order ) == 0 and len (self ._dependency_graph .keys ()) == 0 :
188+ elif items_count > 1 and len (self ._topological_order ) == 0 and len (self ._reverse_dependency_graph .keys ()) == 0 :
181189 self ._execute_status_message = "Multiple steps but no connections to create workflow."
182190 return 3
183191 elif self ._current != - 1 :
@@ -223,8 +231,8 @@ def execute(self):
223231 # But don't use this as it is not what is documented.
224232 # source_step = connection.source()._step
225233 # destination_step = current_node._step
226- # source_ports = [port for port in source_step._ports if port.has_provides ()]
227- # destination_ports = [port for port in destination_step._ports if port.has_uses ()]
234+ # source_ports = [port for port in source_step._ports if port.hasProvides ()]
235+ # destination_ports = [port for port in destination_step._ports if port.hasUses ()]
228236 # source_data_index = source_ports.index(source_step._ports[connection.sourceIndex()])
229237 # destination_data_index = destination_ports.index(destination_step._ports[connection.destinationIndex()])
230238
0 commit comments