Skip to content

Conversation

@DPeterK
Copy link
Member

@DPeterK DPeterK commented Oct 13, 2017

All the PP save rules were supplied by a text file lib/iris/etc/pp_save_rules.txt but the text rule processing classes in lib/iris/fileformats/rules.py are deprecated. This PR, therefore, takes the text rules and translates them into a new Python module lib/iris/fileformats/pp_save_rules.py and makes the necessary changes to PP save so that the new save rules are run.

The old text rules have been updated and a very few test changes have been made – but, of course, this job will have been done correctly if the tests all pass as-is with the exception of the odd API change.

This unblocks #2782.

self.patcher.start()

def tearDown(self):
self.patcher.stop()
Copy link
Member

Choose a reason for hiding this comment

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

@dkillick Might want to take a peek at iris.tests.patch ...

Copy link
Member

@corinnebosley corinnebosley left a comment

Choose a reason for hiding this comment

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

I have paired with Pete on this one, and I'm satisfied that the changes we made were all covered by existing tests and that the functionality has not changed, so this is good to go. Big tick from me.

'default': np.dtype('>f4'),
}

# LBPROC codes and their English equivalents
Copy link
Member

@pp-mo pp-mo Oct 16, 2017

Choose a reason for hiding this comment

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

I think moving these to iris.fileformats.rules is a mistake, as it the information is specific to PP (and FF), whereas iris.fileformats.rules "ought" to be the home for fileformat-independent rules processing.
They aren't specially tied to implementation of text rules anyway.

In any case, "LBPROC_PAIRS" and "lbproc_map" are perfectly reasonable public elements of the API, so you can't just move them anyway.

In an ideal world I think these would be in "iris.fileformats.um_cf_map", and also "lbroc_map" should be capitalised, but it's a bit late for that...

Copy link
Member

@pp-mo pp-mo Oct 16, 2017

Choose a reason for hiding this comment

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

(from discussion with @dkillick)
The move was introduced because of a circularity problem when iris.fileformats.pp imports iris.fileformats.pp_save_rules, which imports iris.fileformats.pp ...
By putting 'lbproc_map' into rules, then pp_save_rules no longer needed to import pp.

Alternative suggestion: Put LBPROC_PAIRS and lbproc_map inside pp_save_rules itself.
Then to avoid breaking existing API, publish them also in 'pp' by importing them from 'pp_save_rules'.

For better measure, we can fix naming + make them private in pp_save_rules.
Ideally we would "deprecate" this, but I also can't see how?
So, perhaps this really is a suitable case for a major-version breaking change ??

Copy link
Member

Choose a reason for hiding this comment

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

More trouble...
I missed that "lbproc_map" is also used in "pp_rules"
( i.e. "pp_load_rules", perhaps it should now be called that ? )

You can import it there from "pp_save_rules", but that is obviously a rather peculiar dependency ordering.
You cannot import it from 'pp', if 'pp' is to import 'pp_rules' (same circularity problem as before)

In my view, this info really belongs with the other similar stuff in 'um_cf_map'.
To do this properly, we should really put this info into metarelate, and modifytools/gen_translations.py to support it, but I really don't think we have time for that.
In which case, we should just host this translation info in a separate module.
See : DPeterK#12 for worked suggestion ...

Copy link
Member Author

Choose a reason for hiding this comment

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

i.e. "pp_load_rules", perhaps it should now be called that ?

See #2790.

we should just host this translation info in a separate module.

Agreed 👍 Thanks for spotting this, @pp-mo

@LukeC92
Copy link
Contributor

LukeC92 commented Oct 16, 2017

On line 64 of pp.py, _save_rules is set to none. The functionality of _save_rules was removed in a previous pull request and with the changes made in this PR it is now obsolete. It would probably be best to remove lines 64 (and maybe 63) now. Otherwise I see no issues with this PR and would approve it.

pp-mo and others added 2 commits October 16, 2017 14:32
* Move lbproc_map to avoid circular import

* Reorganisation of pp lbproc_pairs feature.
@corinnebosley corinnebosley merged commit 538f0d6 into SciTools:master Oct 16, 2017
@corinnebosley
Copy link
Member

Finally!! Pats on the back all round for that one.

@DPeterK DPeterK deleted the pp_save_rules_py branch October 16, 2017 14:39
@QuLogic QuLogic added this to the v2.0 milestone Oct 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants