Skip to content

Commit

Permalink
Fixes child retrieval for fields (#256)
Browse files Browse the repository at this point in the history
* Fixes child retrieval for fields

* Write at correct location in template

* Fixes the issue with TRANSFORMATIONS group

---------

Co-authored-by: Sherjeel Shabih <[email protected]>
  • Loading branch information
domna and sherjeelshabih authored Feb 23, 2024
1 parent 743cf7d commit aef6ccd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<<NOT_FOUND>>" else "optional"
)
template[optionality][f"{path.rsplit('/', 1)[0]}/{child}"] = None
template[optionality][f"{path}/{child}"] = None
return template


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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("/")

Expand All @@ -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


Expand Down Expand Up @@ -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 "
Expand Down

0 comments on commit aef6ccd

Please sign in to comment.