From aef6ccd99035f062ebc9636174191f65b6148859 Mon Sep 17 00:00:00 2001 From: Florian Dobener Date: Fri, 23 Feb 2024 09:14:26 +0100 Subject: [PATCH] Fixes child retrieval for fields (#256) * Fixes child retrieval for fields * Write at correct location in template * Fixes the issue with TRANSFORMATIONS group --------- Co-authored-by: Sherjeel Shabih --- pynxtools/dataconverter/helpers.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pynxtools/dataconverter/helpers.py b/pynxtools/dataconverter/helpers.py index 177f93486..9ea259296 100644 --- a/pynxtools/dataconverter/helpers.py +++ b/pynxtools/dataconverter/helpers.py @@ -112,13 +112,13 @@ def get_all_defined_required_children(nxdl_path, nxdl_name): def add_inherited_children(list_of_children_to_add, path, nxdl_root, template): """Takes a list of child names and appends them to template for a given path.""" for child in list_of_children_to_add: - child_path = f"{path.rsplit('/', 1)[0]}/{child}" + child_path = f"{path}/{child}" if child_path not in template.keys(): optional_parent = check_for_optional_parent(child_path, nxdl_root) optionality = ( "required" if optional_parent == "<>" else "optional" ) - template[optionality][f"{path.rsplit('/', 1)[0]}/{child}"] = None + template[optionality][f"{path}/{child}"] = None return template @@ -164,9 +164,9 @@ def generate_template_from_nxdl( ): template[optionality][f"{path}/@units"] = None - parent_path = convert_data_converter_dict_to_nxdl_path(path.rsplit("/", 1)[0]) + nxdl_path = convert_data_converter_dict_to_nxdl_path(path) list_of_children_to_add = get_all_defined_required_children( - parent_path, nxdl_name + nxdl_path, nxdl_name ) add_inherited_children(list_of_children_to_add, path, nxdl_root, template) @@ -482,6 +482,7 @@ def check_optionality_based_on_parent_group(path, nxdl_path, nxdl_root, data, te def is_group_part_of_path(path_to_group: str, path_of_entry: str) -> bool: """Returns true if a group is contained in a path""" + tokens_group = path_to_group.split("/") tokens_entry = convert_data_converter_dict_to_nxdl_path(path_of_entry).split("/") @@ -491,6 +492,7 @@ def is_group_part_of_path(path_to_group: str, path_of_entry: str) -> bool: for tog, toe in zip(tokens_group, tokens_entry): if tog != toe: return False + return True @@ -530,6 +532,7 @@ def ensure_all_required_fields_exist(template, data, nxdl_root): if not does_group_exist(renamed_path, data): logger.warning(f"The required group, {path}, hasn't been supplied.") continue + continue if not is_path_in_data_dict or data[renamed_path] is None: logger.warning( f"The data entry corresponding to {path} is required "