From 6904a74240dd9978b8979723cd732f213d5d442e Mon Sep 17 00:00:00 2001 From: Vasu Jaganath Date: Tue, 12 Nov 2024 14:29:38 -0500 Subject: [PATCH] fix re-serializing 'string' input and general array input --- src/sophios/compiler.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/sophios/compiler.py b/src/sophios/compiler.py index 62e1aaba..9af62be2 100644 --- a/src/sophios/compiler.py +++ b/src/sophios/compiler.py @@ -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 @@ -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']} @@ -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)