-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement custom loading of pybindings to replace imp.load_dynamic
#131
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to continue limping along with python2 support? I'd rather just drop it wholesale at this point, to be honest.
There are a number of places where people have already broken python 2 compatibility (although I think all would be fixable if there were a reason to care); I mostly just wanted to make sure I wouldn't create an unnecessary limitation in this added code. The portion of this code needed to support it is a fairly small fraction of the whole, and aside from removing some #ifdef blocks, removing it wouldn't provide much simplification. |
I've fixed this on the master branch. Newer versions of astropy expect the transform_to argument to be an initialized instance of the coordinate class. |
Is there a particular reason we don't name the libraries using the standard convention? Seems like an easy solution would be to name the libraries the way that python expects... |
That requires breaking with the conventions expected by everything else for library naming, which make it annoying to link anything else with them. The reason this situation is weirder/harder for us than for most anyone else is that combining python bindings into the same library which is used when python is not (directly) involved is highly atypical. |
Can we use symlinks for one or the other? |
Ping here, it sounds like people are starting to run into this issue more often with updated software. Is this PR ok to merge? |
Sorry about the delay, I was trying to do a bit more checking of the other approach with symlinks to present the same libraries with two different names. That seems to fundamentally work, but there's some detail that I can't quite get right. A few notes in case we ever want to re-visit it: The main change is to install a symlink with an ugly name (e.g.
The leading underscore (or some equivalent mangling) is important for an
In testing, this works, except for importing the modules with compiled components besides At any rate, it seems like we should be able to re-evaluate or change how we do this in future if we want, so I think it's safe to merge the custom loader version for now. |
Sure sounds like witchcraft to me! Yeah, I think it would be nicer in the long run if we didn't have to roll our own loader, so let's revisit at some point. What about if you used a relative import instead, e.g. |
Unfortunately, the relative import yields the same error. It seems like it is finding the symlink (one would hope for a different error if not), but it's adamant that the symbol isn't in the library, even though |
Gremlins. Ok, some more head-scratching for later, this solution is fine for the time being. Thanks for putting in the work! |
Write our own dynamic loading and module initialization code which does not depend on the
imp
module. This breaks the dilemma between theimp
module being removed in python 3.12 and not being able to load the python bindings via the standardimport
mechanism because the library names do not conform to python's non-standard expectations.An
SPT3G_PYTHON_MODULE
macro is introduced to wrapBOOST_PYTHON_MODULE
. This is needed to work around an awkward detail of how python modules are initialized:This causes problems because each class created within a module takes the module object's name to form its own fully-qualified name, so for those to be correct, we need to patch the modules
__name__
after it is created (byPyModule_Create
/Py_InitModule
), but before any of its own initialization code starts running. The new wrapper macro allows us to insert the fix-up code which does this. (It would be elegant to use the same interface that python uses internally to havePyModule_Create
/Py_InitModule
just do the right thing for us, but that interface is private and has not been stable across versions.)This has been tested on python 2.7, 3.7, 3.8, and 3.12.
There is one test failure on python 3.12, however, it appears to be unrelated:
as the problem can be reproduced by a reduced test-case which does not involve spt3g_software, suggesting that the cause is an
astropy
bug:There are also various test failures on python 2.7, but they appear to involve various cases of invalid (too-new) syntax in existing scripts, but other scripts without those issues work, and most tests pass.
Addresses #127