pont-us / PuffinPlot

A program to plot and analyse palaeomagnetic data
GNU General Public License v3.0
3 stars 0 forks source link

Add file import hooks #380

Open pont-us opened 3 years ago

pont-us commented 3 years ago

Someone suggested this at Magnetic Moments 2018. I should open up the file import API to allow hooking in third-party file import code at runtime. Seems an excellent idea, if anyone's actually up to using it :).

Actually the file loading API needs tidying up anyway, so it would be as well to consider pluggability when redesigning it.

One idea: Suite.loadFiles should no longer take a filetype enum and option map, but an already instantiated FileLoader object. File reading should be moved out of the constructors (that was a bad decision from the start). Instead the constructor should just set any supplied options (including the file / input stream?). Add an instance method to the interface for actually reading the file.

If the interface is going to be pluggable we probably need to ditch the FileType enum. Instead, PuffinApp needs a registerFileLoader() method taking a Class object. It can register its own known file loaders on start-up, and new ones can be added by e.g. running a Python script that defines a new class and calls the registration method with it. For operation within a script, registration won't be needed of course: one simply instantiates the class and passes it to Suite.readFiles.