Skip to content

Commit

Permalink
Utility class in netcdf loader should not be public. (#4592)
Browse files Browse the repository at this point in the history
* Utility class in netcdf loader should not be public.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename container for better clarity.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pp-mo and pre-commit-ci[bot] authored Feb 17, 2022
1 parent 70583f9 commit 8f3e3b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/iris/fileformats/_nc_load_rules/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
3) Iris-specific info is (still) stored in additional properties created on
the engine object :
engine.cf_var, .cube, .cube_parts, .requires, .rule_triggered, .filename
engine.cf_var, .cube, .cube_parts, .requires, .rules_triggered, .filename
Our "rules" are just action routines.
The top-level 'run_actions' routine decides which actions to call, based on the
Expand Down Expand Up @@ -78,7 +78,7 @@ def inner(engine, *args, **kwargs):
# but also may vary depending on whether it successfully
# triggered, and if so what it matched.
rule_name = _default_rulenamesfunc(func.__name__)
engine.rule_triggered.add(rule_name)
engine.rules_triggered.add(rule_name)

func._rulenames_func = _default_rulenamesfunc
return inner
Expand Down
26 changes: 17 additions & 9 deletions lib/iris/fileformats/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _actions_activation_stats(engine, cf_name):

print("Rules Triggered:")

for rule in sorted(list(engine.rule_triggered)):
for rule in sorted(list(engine.rules_triggered)):
print("\t%s" % rule)

print("Case Specific Facts:")
Expand Down Expand Up @@ -570,13 +570,21 @@ def _get_cf_var_data(cf_var, filename):
return as_lazy_data(proxy, chunks=chunks)


class OrderedAddableList(list):
# Used purely in actions debugging, to accumulate a record of which actions
# were activated.
# It replaces a set, so as to record the ordering of operations, with
# possible repeats, and it also numbers the entries.
# Actions routines invoke the 'add' method, which thus effectively converts
# a set.add into a list.append.
class _OrderedAddableList(list):
"""
A custom container object for actions recording.
Used purely in actions debugging, to accumulate a record of which actions
were activated.
It replaces a set, so as to preserve the ordering of operations, with
possible repeats, and it also numbers the entries.
The actions routines invoke an 'add' method, so this effectively replaces
a set.add with a list.append.
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._n_add = 0
Expand All @@ -602,7 +610,7 @@ def _load_cube(engine, cf, cf_var, filename):
engine.cube = cube
engine.cube_parts = {}
engine.requires = {}
engine.rule_triggered = OrderedAddableList()
engine.rules_triggered = _OrderedAddableList()
engine.filename = filename

# Assert all the case-specific facts.
Expand Down

0 comments on commit 8f3e3b9

Please sign in to comment.