xarray-contrib / xarray-simlab

Xarray extension and framework for computer model simulations
http://xarray-simlab.readthedocs.io
BSD 3-Clause "New" or "Revised" License
73 stars 9 forks source link

Decouple process class from Model #63

Closed benbovy closed 5 years ago

benbovy commented 5 years ago

This is a follow-up on #59 towards a less invasive framework.

@process is now a thin wrapper around attr.s. Applied on a class A, it returns the class (almost) just as it was decorated with attr.s. The more invasive modifications (custom properties, etc.) are now in a subclass of A that is created programmatically and accessible from A.__xsimlab_cls__ (Model objects use the latter subclass instead of A directly).

The great advantage is that it is now possible to use instances of process-decorated classes independently of any Model, which is IMO a better solution than the approach proposed in #50 for testing the logic implemented in those classes.

Variables declared with intent='in' or intent='inout' are now included in__init__ generated by attr.

An alternative approach would be to stick with one single class and customize its __init__ to circumvent the limitation of read-only properties created for input variables (see, e.g., https://github.com/python-attrs/attrs/issues/393#issuecomment-510148031). This is maybe less complicated than the approach used here, but it still alters the class significantly.

TODO: