Skip to content

Commit f0894f1

Browse files
committed
dynamic get_list() function
1 parent f72e7f1 commit f0894f1

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

python_workflow_definition/src/python_workflow_definition/pyiron_workflow.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def import_from_string(library_path: str) -> Any:
209209
return obj
210210

211211

212-
def generate_function(args_of_lst):
212+
def generate_get_dict_function(args_of_lst):
213213
lines = "def get_dict(" + ", ".join(args_of_lst) + "):\n"
214214
lines += " return {\n"
215215
for parameter in args_of_lst:
@@ -218,6 +218,15 @@ def generate_function(args_of_lst):
218218
return lines
219219

220220

221+
def generate_get_list_function(args_of_lst):
222+
lines = "def get_list(" + ", ".join(args_of_lst) + "):\n"
223+
lines += " return [\n"
224+
for parameter in args_of_lst:
225+
lines += " " + parameter + ",\n"
226+
lines += " ]"
227+
return lines
228+
229+
221230
def load_workflow_json(file_name: str) -> Workflow:
222231
content = remove_result(
223232
PythonWorkflowDefinitionWorkflow.load_json_file(file_name=file_name)
@@ -236,15 +245,26 @@ def load_workflow_json(file_name: str) -> Workflow:
236245
if node_dict["type"] == "function":
237246
if node_dict["value"] == "python_workflow_definition.shared.get_dict":
238247
exec(
239-
generate_function(
248+
generate_get_dict_function(
240249
args_of_lst=[
241250
edge[TARGET_PORT_LABEL]
242251
for edge in content[EDGES_LABEL]
243-
if edge[TARGET_LABEL] == node_dict["value"]
252+
if edge[TARGET_LABEL] == node_dict["id"]
244253
]
245254
)
246255
)
247256
fnc = eval("get_dict")
257+
elif node_dict["value"] == "python_workflow_definition.shared.get_list":
258+
exec(
259+
generate_get_list_function(
260+
args_of_lst=[
261+
edge[TARGET_PORT_LABEL]
262+
for edge in content[EDGES_LABEL]
263+
if edge[TARGET_LABEL] == node_dict["id"]
264+
]
265+
)
266+
)
267+
fnc = eval("get_list")
248268
else:
249269
fnc = import_from_string(node_dict["value"])
250270
if total_counter_dict[node_dict["value"]] > 1:

0 commit comments

Comments
 (0)