Skip to content

Commit

Permalink
suppress info about link removal with suppress_warning
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspie committed Nov 22, 2024
1 parent 6b01efc commit 5ecf6f1
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/pynxtools/dataconverter/readers/multi/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,27 @@ def parse_config_value(value: str) -> Tuple[str, Any]:
if new_entry_dict[key] is not None:
break

if (
value.startswith("!")
and isinstance(new_entry_dict[key], dict)
and "link" in new_entry_dict[key]
):
if isinstance(new_entry_dict[key], dict) and "link" in new_entry_dict[key]:
link_target = new_entry_dict[key]["link"]
print("link_target", link_target)
logger.info(
f"There was no target at {link_target} for the optional link for {key}. "
f"Removing the link."
)
del new_entry_dict[key]
return
if (
link_target.startswith("!")
and link_target.lstrip("!") not in new_entry_dict
):
if not suppress_warning:
logger.info(
f"There was no target at {link_target.lstrip('!')} for the optional link defined for {key}. "
f"Removing the link."
)
del new_entry_dict[key]
return

if value.startswith("!") and new_entry_dict[key] is None:
group_to_delete = key.rsplit("/", 1)[0]
logger.info(
f"Main element {key} not provided. "
f"Removing the parent group {group_to_delete}."
)
if not suppress_warning:
logger.info(
f"Main element {key} not provided. "
f"Removing the parent group {group_to_delete}."
)
optional_groups_to_remove.append(group_to_delete)
return

Expand Down Expand Up @@ -272,14 +273,15 @@ def has_missing_main(key: str) -> bool:

def dict_sort_key(keyval: Tuple[str, Any]) -> Tuple[int, str]:
"""
Sort keys by their value's priority:
- Values starting with "!link" go last (return 2).
Sort the dict by:
- Values starting with "@link:!" go last (return 2).
This is for optional links that are first check to work.
- Values starting with "!" but not "!link" go first (return 0).
- All other values are sorted normally (return 1).
"""
value = keyval[1]
if isinstance(value, str):
if value.startswith("!@link"):
if value.startswith("@link:!"):
return (2, keyval[0]) # Last
if value.startswith("!"):
return (0, keyval[0]) # First
Expand All @@ -292,10 +294,8 @@ def dict_sort_key(keyval: Tuple[str, Any]) -> Tuple[int, str]:
optional_groups_to_remove: List[str] = []
new_entry_dict = {}

# Process '!...' keys first, but '!link' keys last
# Process '!...' keys first, but optional link last
sorted_keys = dict(sorted(config_dict.items(), key=dict_sort_key))
for key, val in sorted_keys.items():
print(key, val)

for entry_name in entry_names:
callbacks.entry_name = entry_name
Expand Down

0 comments on commit 5ecf6f1

Please sign in to comment.