Open oliver-s-lee opened 3 months ago
This is how all our optional dependencies work (such as the bridges), though Open Babel is the most pervasive in the codebase. Outside of the bridge my understanding is the same as yours, that it's only for fallback file reading.
My thoughts are:
My thoughts are largely the same. Personally, I don't mind putting rare, optional imports like this in the function body itself (in fact I would argue it's more appropriate there), but I know some people really don't like this style.
Re. obabel 2 vs 3, I would suggest not forcing the migration yet just because of the number of ancient computing clusters out in the wild. In my (limited) experience, the chance of finding obabel 2 vs 3 is probably close to 50:50
While we're on the topic are we ok with importing obabel at all considering GPL? I have no idea what the consensus is for optional imports etc.
Personally, I don't mind putting rare, optional imports like this in the function body itself (in fact I would argue it's more appropriate there), but I know some people really don't like this style.
I would agree but also like the ability to give a more informative error message when an optional dependency isn't found other than "error: no module named xyz".
Re. obabel 2 vs 3, I would suggest not forcing the migration yet just because of the number of ancient computing clusters out in the wild. In my (limited) experience, the chance of finding obabel 2 vs 3 is probably close to 50:50
Ok, that's fine. But I am now wondering about what version of Python is being used.
I would agree but also like the ability to give a more informative error message when an optional dependency isn't found other than "error: no module named xyz".
Yeah that makes sense, I'm sure we can incorporate that into a function.
Ok, that's fine. But I am now wondering about what version of Python is being used.
That's a good point, probably still a lot of 3.6 out there...
This issue is inspired by a hotfix I quickly wrote to solve a strange openbabel import error, but I thought it was worth a wider discussion because of a few more issues that are worth addressing.
Currently, in a few places (at least
cclib/io/filewriter.py
andcclib/io/ccio.py
) we do something like this:The specific error that I've fixed is that it's possible (at least in older Babel 2.0) to install openbabel but not pybel. In this case,
filewriter.py
is not importable. More importantly, through a series of import hops, filewriter gets imported from the main cclib__init__.py
file, meaning that no part of cclib is usable on such a system (even though the openbabel bits probably aren't getting used).The current patch is something like:
But this is really a bit backwards, more properly we should be doing something like:
More generally though, it feels strange to be importing openbabel at the module level at all, considering it's not formally a dependency of cclib and it's mostly used for fallback stuff afaik? Having
import cclib
end up doingimport openbabel
was a bit of a surprise for me at least...