diff --git a/src/vai_lab/Core/vai_lab_core.py b/src/vai_lab/Core/vai_lab_core.py index 3eb4ad19..ebe9ca5d 100644 --- a/src/vai_lab/Core/vai_lab_core.py +++ b/src/vai_lab/Core/vai_lab_core.py @@ -47,9 +47,9 @@ def load_config_file(self, filename: Union[str,List,Tuple]): self._xml_handler.load_XML(filedir) self._initialised = True - def _load_data(self, module = 'Initialiser') -> None: + def _load_data(self, specs, module = 'Initialiser') -> None: """Loads data from XML file into Data object""" - init_data_fn = self._xml_handler.data_to_load(module) + init_data_fn = self._xml_handler.data_to_load(modules=specs, module=module) if module not in self.data.keys(): self.data[module] = Data() if isinstance(init_data_fn, str): @@ -66,7 +66,7 @@ def _execute_module(self, specs): mod: ModuleInterface = import_module(globals(), specs["module_type"]).__call__() mod._debug = self._debug mod.set_avail_plugins(self._avail_plugins) - self._load_data(specs["name"]) + self._load_data(specs, specs["name"]) mod.set_data_in(self.data[specs["name"]]) mod.set_options(specs) print("\t"*self.loop_level @@ -185,7 +185,7 @@ def run(self): self._initialise_with_gui() print("Running pipeline...") if len(self._xml_handler.loaded_modules) > 0: - self._load_data() + self._load_data(self._xml_handler.loaded_modules) self._init_status(self._xml_handler.loaded_modules) self._execute(self._xml_handler.loaded_modules) diff --git a/src/vai_lab/Data/xml_handler.py b/src/vai_lab/Data/xml_handler.py index bbb1bb14..0e7e5697 100644 --- a/src/vai_lab/Data/xml_handler.py +++ b/src/vai_lab/Data/xml_handler.py @@ -200,9 +200,10 @@ def _load_options(self, element: ET.Element, parent: dict) -> None: """ for child in element: if child.text is not None: - val = self._parse_text_to_list(child) - val = (val[0] if len(val) == 1 else val) - parent["options"][child.tag] = val + try: + parent["options"][child.tag] = literal_eval(child.text.strip()) + except Exception as exc: + parent["options"][child.tag] = child.text.strip() for key in child.attrib: if key == "val": @@ -718,10 +719,15 @@ def append_pipeline_loop(self, xml_parent_element.append(new_loop) - def _get_data_structure(self, module) -> Dict[str, Any]: - data_struct = self._find_dict_with_key_val_pair( - self.loaded_modules[module], - "class", "data") + def _get_data_structure(self, modules, module) -> Dict[str, Any]: + try: + data_struct = self._find_dict_with_key_val_pair( + modules[module], + "class", "data") + except Exception as exc: + data_struct = self._find_dict_with_key_val_pair( + modules, + "class", "data") assert len(data_struct) < 2, \ "Multiple data with same ID, please check XML" @@ -734,8 +740,10 @@ def _get_data_structure(self, module) -> Dict[str, Any]: return out #@property - def data_to_load(self, module='Initialiser') -> Dict[str, str]: - return self._get_data_structure(module)["to_load"] + def data_to_load(self, modules=False, module='Initialiser') -> Dict[str, str]: + if not modules: + modules = self.loaded_modules + return self._get_data_structure(modules, module)["to_load"] # Use case examples: