Skip to content

Commit 131e4a8

Browse files
vjaganat90Vasu Jaganath
andauthored
fix re-serializing 'string' input and general array input (PolusAI#297)
Co-authored-by: Vasu Jaganath <[email protected]>
1 parent 441b1a0 commit 131e4a8

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/sophios/compiler.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from pathlib import Path
66
import sys
7-
from typing import Dict, List
7+
from typing import Dict, List, Any
88

99
import graphviz
1010
from mergedeep import merge, Strategy
@@ -861,10 +861,8 @@ def compile_workflow_once(yaml_tree_ast: YamlTree,
861861
steps_list.append(step_i_copy)
862862
yaml_tree.update({'steps': steps_list}) # steps_list ?
863863

864-
# Dump the workflow inputs to a separate yml file.
865-
yaml_inputs: WorkflowInputsFile = {}
866-
for key, in_dict in inputs_file_workflow.items():
867-
new_keyval: WorkflowInputsFile = {}
864+
def populate_scalar_val(in_dict: dict) -> Any:
865+
newval: Any = ()
868866
if 'File' == in_dict['type']:
869867
# path = Path(in_dict['value']).name # NOTE: Use .name ?
870868
newval = {'class': 'File', 'path': in_dict['value']}
@@ -878,15 +876,28 @@ def compile_workflow_once(yaml_tree_ast: YamlTree,
878876
print(f'Choosing {in_format[0]}')
879877
in_format = in_format[0]
880878
newval['format'] = in_format
881-
new_keyval = {key: newval}
882879
elif 'Directory' == in_dict['type']:
883880
newval = {'class': 'Directory', 'location': in_dict['value']}
884-
new_keyval = {key: newval}
881+
elif 'string' == in_dict['type'] or 'string?' == in_dict['type']:
882+
# We cannot store string values as a dict, so use type: ignore
883+
newval = str(in_dict['value'])
885884
# TODO: Check for all valid types?
886885
else:
887-
# We cannot store string values as a dict, so use type: ignore
888-
arg_val = in_dict['value']
889-
new_keyval = {key: arg_val}
886+
newval = in_dict['value']
887+
return newval
888+
889+
# Dump the workflow inputs to a separate yml file.
890+
yaml_inputs: WorkflowInputsFile = {}
891+
for key, in_dict in inputs_file_workflow.items():
892+
new_keyval: WorkflowInputsFile = {}
893+
if isinstance(in_dict['type'], dict) and 'array' == in_dict['type']['type']:
894+
val_list = []
895+
for val in in_dict['value']:
896+
val_list.append(populate_scalar_val(
897+
{'type': in_dict['type']['items'], 'value': val, 'format': in_dict.get('format')}))
898+
new_keyval = {key: val_list}
899+
else:
900+
new_keyval = {key: populate_scalar_val(in_dict)}
890901
# else:
891902
# raise Exception(f"Error! Unknown type: {in_dict['type']}")
892903
yaml_inputs.update(new_keyval)

0 commit comments

Comments
 (0)