astropy/astropy — pull request #2063 by astrofrog (2014-02-07 18:34:51+00:00)
Title: WIP: Use classes for readers/writers and use a metaclass for auto-registering

**This is work in progress - do not merge!**

This goes towards addressing the issue in #1046 of using classes to define readers/writers, and uses a metaclass adapted from the one currently in ``astropy.io.ascii`` to auto-register the readers/writers. I also implemented a FITS reader/writer for NDData and found that this resulted in additional circular imports which motivated some of the refactoring here.

A few things I'm still not happy with:

* [ ] I don't like the use of ``partial`` to get around the fact that the methods require the first argument to be ``self`` but we are calling them like class methods.
* [ ] Importing the connectors has now been moved to ``read`` and ``write`` to avoid circular imports. However, I find this still sub-optimal because I had to write the ``import_connectors`` function in ``registry`` which still has the hard-coded imports (this is to make sure the classes get defined, otherwise they don't and don't get auto-registered!).

In addition I still need to integrate ``astropy.io.ascii`` into this new system (if we go ahead with it).

Of course, there are tests, docs, etc. missing from here, but this is just a prototype at this stage.

@taldcroft - could you let me know what you think of this so far? How do you think we should deal with ``astropy.io.ascii``? Should it use a separate metaclass, or should it be integrated into the new system?

Once this is all in place we can also try and see whether we can use it to improve the documentation situation, by building the ``Table.read/Table.write`` and ``NDData.read/NDData.write`` docstrings dynamically using the metaclass.