WIP: Use classes for readers/writers and use a metaclass for auto-registering#2063
WIP: Use classes for readers/writers and use a metaclass for auto-registering#2063astrofrog wants to merge 9 commits into
Conversation
…ng I/O routines for e.g. Table and NDData
… all registered by the time the module was imported)
|
To avoid seeing all the indent changes due to putting functions in classes: |
There was a problem hiding this comment.
Should this maybe also include ''? Sometimes blank keywords are considered to contain "useful" metadata. Though in this case it might not be well preserved either. Hard to say...
|
@astrofrog - Sorry, I'm a bit swamped with things at the moment but will try to take a look this week. |
|
@astrofrog - I've been looking at this in the background and thinking about it. I don't have any fully formulated ideas, but the first thing that strikes me is that it seems this doesn't take full advantage of using classes in the sense that it still just registers the reader/writer/identifier functions (though they are now methods). I was originally thinking more about registering classes or class instances. There is some opportunity to be lightweight in the sense of lazy loading where possible. We still haven't solved the inline documentation problem. I'm stuck because at the moment because to do that would require essentially loading all of io.fits, io.ascii, etc in order to know all the available readers and their docs. I don't want this to happen as an immediate side effect if importing Table, but it could happen at the moment you ask Anyway, just want to let you know I haven't forgotten this. |
|
@taldcroft - I also was thinking about this and coming to the same conclusion that we could just register the classes and have the registry automatically read all the information from the class. There is one solution to the documentation problem, which while not elegant, would certainly save us a lot of hassle. The solution is simply to move In some ways it'd also be easier to keep all the connectors in one place, as it's easier to make them more consistent with each others. Do you have any thoughts on this? |
|
I think I'm also on the same page as @taldcroft on this, and it looks like you might be coming to the same conclusions too, so that's good. The way I saw it, I figured you were doing things the way you were for backwards compatibility with the original reader/writer registry. But I don't think that system is used much outside of Astropy itself...? (do any affiliated packages use it?) I would want to keep it around a bit longer for backwards compatibility anyways, but the new registry should probably avoid it and take more advantage of the use of classes. |
|
I'm also okay on the |
|
Sounds good - I'll give the |
|
There is this conflict between keeping things light via external definition of readers vs. importing the actual code. With So imagine having a @astrofrog - I might have an idea of how to get all this to congeal together, but it's a little fuzzy still. Can I take a crack at this? If you are psyched to do this then that's fine of course. |
|
@taldcroft - please do feel free to have a go at this! You can start from scratch and don't need to include the commits here. I'm short on time over the next week or so. |
|
@taldcroft - just to check, are you still planning to have a go at this? |
|
@astrofrog - errr, I got distracted before getting a chance at this and now I'm thinking about coordinates and table stuff.. I can give you back the baton on this. |
|
@taldcroft - no problem, just wanted to check. I'll see if I can work on it during a flight at the weekend, so if you have any other comments in addition to those you added above, let me know! |
|
As I'm further investigating import times, one thing I've discovered is that importing |
|
@mdboom - keeping the |
|
This is superseded by #3090 |
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.asciito 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:
partialto get around the fact that the methods require the first argument to beselfbut we are calling them like class methods.readandwriteto avoid circular imports. However, I find this still sub-optimal because I had to write theimport_connectorsfunction inregistrywhich 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.asciiinto 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.writeandNDData.read/NDData.writedocstrings dynamically using the metaclass.