Skip to content

Commit fbbcc08

Browse files
committed
black formatting
1 parent 3bdaee6 commit fbbcc08

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

python_workflow_definition/src/python_workflow_definition/pyiron_workflow.py

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ def get_linked_nodes(graph_dict):
2525
nodes_dict[i] = v.node_function
2626
node_mapping_dict[k] = i
2727
input_dict[k] = {
28-
con.full_label: con.value
29-
for con in v.inputs.channel_dict.to_list()
28+
con.full_label: con.value
29+
for con in v.inputs.channel_dict.to_list()
3030
if len(con.connections) == 0
3131
}
3232
return nodes_dict, node_mapping_dict, input_dict
3333

3434

35-
36-
3735
def extend_nodes_dict(nodes_dict, input_dict):
3836
i = len(nodes_dict)
3937
nodes_links_dict = {}
@@ -44,30 +42,42 @@ def extend_nodes_dict(nodes_dict, input_dict):
4442
nodes_links_dict[k] = i
4543
i += 1
4644
else:
47-
nodes_links_dict[k] = {tv:tk for tk, tv in nodes_dict.items()}[v]
45+
nodes_links_dict[k] = {tv: tk for tk, tv in nodes_dict.items()}[v]
4846
return nodes_links_dict
4947

5048

51-
52-
5349
def get_edges(graph_dict, node_mapping_dict, nodes_links_dict):
5450
edges_lst = []
5551
for link in list(graph_dict["edges"]["data"].keys()):
5652
source_combo, target_combo = link
5753
target, target_handle = target_combo.split(".")
5854
source, source_handle = source_combo.split(".")
59-
edges_lst.append({TARGET_LABEL: node_mapping_dict[target], TARGET_PORT_LABEL: target_handle, SOURCE_LABEL: node_mapping_dict[source], SOURCE_PORT_LABEL: source_handle})
55+
edges_lst.append(
56+
{
57+
TARGET_LABEL: node_mapping_dict[target],
58+
TARGET_PORT_LABEL: target_handle,
59+
SOURCE_LABEL: node_mapping_dict[source],
60+
SOURCE_PORT_LABEL: source_handle,
61+
}
62+
)
6063

6164
for k, v in nodes_links_dict.items():
6265
target, target_handle = k.split(".")
63-
edges_lst.append({TARGET_LABEL: node_mapping_dict[target], TARGET_PORT_LABEL: target_handle, SOURCE_LABEL: v, SOURCE_PORT_LABEL: None})
66+
edges_lst.append(
67+
{
68+
TARGET_LABEL: node_mapping_dict[target],
69+
TARGET_PORT_LABEL: target_handle,
70+
SOURCE_LABEL: v,
71+
SOURCE_PORT_LABEL: None,
72+
}
73+
)
6474
return edges_lst
6575

6676

67-
def write_workflow_json(
68-
graph_as_dict: dict, file_name: str = "workflow.json"
69-
):
70-
nodes_dict, node_mapping_dict, input_dict = get_linked_nodes(graph_dict=graph_as_dict)
77+
def write_workflow_json(graph_as_dict: dict, file_name: str = "workflow.json"):
78+
nodes_dict, node_mapping_dict, input_dict = get_linked_nodes(
79+
graph_dict=graph_as_dict
80+
)
7181
nodes_links_dict = extend_nodes_dict(nodes_dict=nodes_dict, input_dict=input_dict)
7282
edges_lst = get_edges(
7383
graph_dict=graph_as_dict,
@@ -105,12 +115,14 @@ def write_workflow_json(
105115
nodes_to_delete.append(edge[SOURCE_LABEL])
106116
else:
107117
source = edge[SOURCE_LABEL]
108-
edge_new_lst.append({
109-
SOURCE_LABEL: source,
110-
SOURCE_PORT_LABEL: sourcehandle,
111-
TARGET_LABEL: source_dict[k][-1][TARGET_LABEL],
112-
TARGET_PORT_LABEL: source_dict[k][-1][TARGET_PORT_LABEL],
113-
})
118+
edge_new_lst.append(
119+
{
120+
SOURCE_LABEL: source,
121+
SOURCE_PORT_LABEL: sourcehandle,
122+
TARGET_LABEL: source_dict[k][-1][TARGET_LABEL],
123+
TARGET_PORT_LABEL: source_dict[k][-1][TARGET_PORT_LABEL],
124+
}
125+
)
114126

115127
nodes_to_skip = nodes_to_delete + list(pyiron_workflow_modules.keys())
116128
nodes_new_dict = {k: v for k, v in nodes_dict.items() if k not in nodes_to_skip}
@@ -130,7 +142,10 @@ def write_workflow_json(
130142
nodes_store_lst.append({"id": k, "type": "input", "value": v})
131143

132144
for edge in edges_lst:
133-
if edge[TARGET_LABEL] not in nodes_to_skip and edge[SOURCE_LABEL] not in nodes_to_skip:
145+
if (
146+
edge[TARGET_LABEL] not in nodes_to_skip
147+
and edge[SOURCE_LABEL] not in nodes_to_skip
148+
):
134149
edge_new_lst.append(edge)
135150

136151
nodes_updated_dict, mapping_dict = {}, {}
@@ -143,8 +158,12 @@ def write_workflow_json(
143158
edge_updated_lst = []
144159
for edge in edge_new_lst:
145160
edge_updated_lst.append(
146-
{SOURCE_LABEL: mapping_dict[edge[SOURCE_LABEL]], SOURCE_PORT_LABEL: edge[SOURCE_PORT_LABEL],
147-
TARGET_LABEL: mapping_dict[edge[TARGET_LABEL]], TARGET_PORT_LABEL: edge[TARGET_PORT_LABEL]}
161+
{
162+
SOURCE_LABEL: mapping_dict[edge[SOURCE_LABEL]],
163+
SOURCE_PORT_LABEL: edge[SOURCE_PORT_LABEL],
164+
TARGET_LABEL: mapping_dict[edge[TARGET_LABEL]],
165+
TARGET_PORT_LABEL: edge[TARGET_PORT_LABEL],
166+
}
148167
)
149168

150169
PythonWorkflowDefinitionWorkflow(

0 commit comments

Comments
 (0)