Skip to content

Commit

Permalink
fix re-serializing 'string' input and general array input
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasu Jaganath committed Nov 13, 2024
1 parent 441b1a0 commit 6904a74
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/sophios/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path
import sys
from typing import Dict, List
from typing import Dict, List, Any

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

# Dump the workflow inputs to a separate yml file.
yaml_inputs: WorkflowInputsFile = {}
for key, in_dict in inputs_file_workflow.items():
new_keyval: WorkflowInputsFile = {}
def populate_scalar_val(in_dict: dict) -> Any:
newval: Any = ()
if 'File' == in_dict['type']:
# path = Path(in_dict['value']).name # NOTE: Use .name ?
newval = {'class': 'File', 'path': in_dict['value']}
Expand All @@ -878,15 +876,28 @@ def compile_workflow_once(yaml_tree_ast: YamlTree,
print(f'Choosing {in_format[0]}')
in_format = in_format[0]
newval['format'] = in_format
new_keyval = {key: newval}
elif 'Directory' == in_dict['type']:
newval = {'class': 'Directory', 'location': in_dict['value']}
new_keyval = {key: newval}
elif 'string' == in_dict['type'] or 'string?' == in_dict['type']:
# We cannot store string values as a dict, so use type: ignore
newval = str(in_dict['value'])
# TODO: Check for all valid types?
else:
# We cannot store string values as a dict, so use type: ignore
arg_val = in_dict['value']
new_keyval = {key: arg_val}
newval = in_dict['value']
return newval

# Dump the workflow inputs to a separate yml file.
yaml_inputs: WorkflowInputsFile = {}
for key, in_dict in inputs_file_workflow.items():
new_keyval: WorkflowInputsFile = {}
if isinstance(in_dict['type'], dict) and 'array' == in_dict['type']['type']:
val_list = []
for val in in_dict['value']:
val_list.append(populate_scalar_val(
{'type': in_dict['type']['items'], 'value': val, 'format': in_dict.get('format')}))
new_keyval = {key: val_list}
else:
new_keyval = {key: populate_scalar_val(in_dict)}
# else:
# raise Exception(f"Error! Unknown type: {in_dict['type']}")
yaml_inputs.update(new_keyval)
Expand Down

0 comments on commit 6904a74

Please sign in to comment.