Skip to content
Draft
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
27 changes: 19 additions & 8 deletions fmf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ class AdjustCallback(Protocol):
A callback for per-rule notifications made by Tree.adjust()

Function which will be called for every rule inspected by adjust().
It will be given three arguments: fmf tree being inspected,
current adjust rule, and whether the rule was skipped (``None``),
applied (``True``) or not applied (``False``).
It will be given the following arguments:

* fmf tree being inspected - **after ``adjust``** rule was applied,
* the current adjust rule,
* whether the rule was skipped (``None``), applied (``True``) or not
applied (``False``),
* and if the rule was applied, the original node content.
"""

def __call__(
self,
node: 'Tree',
rule: Dict[str, Any],
applied: Optional[bool]) -> None:
applied: Optional[bool],
before: Optional['Tree'] = None) -> None:
pass


Expand Down Expand Up @@ -584,16 +589,22 @@ def apply_rules(rule_set):
# Apply remaining rule attributes if context matches
try:
if context.matches(condition):
if decision_callback:
decision_callback(self, rule, True)

# Remove special keys (when, because...) from the rule
apply_rule = {
key: value
for key, value in rule.items()
if key not in ADJUST_CONTROL_KEYS
}
self._merge_special(self.data, apply_rule)

if decision_callback:
node_before = self.copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it deep_copy instead in case the merge changes something like a list, or is that already taken care of?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought there's deepcopy used, but when I play with it I see no change between before and after, and I suspect the copy is not as deep as I expected...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, deepcopy is there, and what I saw was PEBKAC.


self._merge_special(self.data, apply_rule)

decision_callback(self, rule, True, before=node_before)

else:
self._merge_special(self.data, apply_rule)

# First matching rule wins, skip the rest of this set unless continue
if not continue_:
Expand Down
Loading