Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# XRLint Change History

## Version 0.5.2 (in development)

- Fixed propagation of global DataTree attributes to child
Datasets and Variables. (#63)


## Version 0.5.1 (from 2025-02-21)

- XRLint now also loads default configuration from files named
Expand Down
22 changes: 20 additions & 2 deletions xrlint/_linter/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,45 @@ def apply_rule(
def _visit_datatree_node(rule_op: RuleOp, context: RuleContextImpl, node: DataTreeNode):
with context.use_state(node=node):
rule_op.validate_datatree(context, node)

current_attrs = node.datatree.attrs.copy()

if node.datatree.is_leaf:
dataset_copy = node.datatree.dataset.copy()
merged_dataset_attrs = {
**current_attrs,
**dataset_copy.attrs,
}
Comment on lines +71 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right. Can you please add a comment explaining why this is done and why it is correct.

Also add a test case that verifies correctness and explains the use case / reproduces the issue.


dataset_copy.attrs = merged_dataset_attrs

_visit_dataset_node(
rule_op,
context,
DatasetNode(
parent=node,
path=f"{node.path}/{node.datatree.name}",
name=node.datatree.name,
dataset=node.datatree.dataset,
dataset=dataset_copy,
),
)
else:
for name, datatree in node.datatree.children.items():
datatree_copy = datatree.copy()

datatree_copy.attrs = {
**current_attrs,
**datatree_copy.attrs,
}
Comment on lines +93 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


_visit_datatree_node(
rule_op,
context,
DataTreeNode(
parent=node,
path=f"{node.path}/{name}",
name=name,
datatree=datatree,
datatree=datatree_copy,
),
)

Expand Down