-
Notifications
You must be signed in to change notification settings - Fork 375
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
RFE: Use Python Stable ABI for the bindings #2345
Comments
In general, this seems interesting to me, though I'm curious about the caveats. (I also generally wonder why this isn't just being introduced as a Python 4 so we can switch Python to major versioned directories instead of major+minor versioned directories...) |
An alternative would be to use CFFI. |
I've always considered the Python API instability between minor versions a massive pain in the behind, so I'm glad to hear this is being addressed - I haven't been paying attention to Python world so this is (good) news to me. So yes, this would be most welcome unless it turns out to somehow unreasonably encumber us. On the outset, the caveats listed here seem non-issues to me:
Thanks for the initiative, and looking forward for the patches 😁 |
OK! How would you prefer me to contribute this? Polish it and submit one big PR, or several smaller ones (with the initial ones not making sense on their own, like dropping Python 3.1)?
The feature is there since 3.2 and has been improved ever since. You can hop on the train at any time, it's not a major version change. Figuring out a better installation layout is probably something distros will need to drive, and this change should give them an incentive :)
I'm suggesting the 3.10 minimum for the stable ABI only. For older versions (down to 3.2), RPM would build a version-specific module, just like before. However even those would have some of the caveats below (unless we put in big #ifdef blocks).
Performance loss comes mostly from macros/inline functions being actual function calls. RPM uses sequence item assignment (
Here's the biggest change/caveat by far: Since the stable ABI doesn't expose memory layout, type definitions need to change. RPM uses For stable ABI, we need to use heap types, which are more similar to classes defined in Python. They're created dynamically from a “spec”. Another difference in heap types is that, like classes defined in Python code, the type object is mutable: for example a user can do |
I'll need to digest this all for a bit, but just a quick note on this:
A feature that makes a big difference makes shooting for 3.7 totally reasonable. |
From my perspective, the minimum I care about is Python 3.9, since that's the RHEL 9 minimum. I would like to have Python 3.6 if we can work it to maintain SLE 15 too, but if there's a big QoL enhancement, I'm okay with just Python 3.9+. |
"Must build on RHEL latest" is the unwritten rule, so if RHEL 9 has 3.9 then that would be a "hard limit" on how new we can go. |
I'm only asking to drop Python 3.1. |
Yes I understood about dropping 3.1, but I'm saying we really do not need to support all those old versions either. Python 3.7 would be an entirely reasonable minimum version to support. |
I had a brief look at the PoC and I don't see anything fundamentally offending in there, more to the contrary (for one, I will not miss those gigantic PyTypeObject initializers). I didn't fine-comb the changes but AIUI there's no functionality change, except for the init-only-once part? In that case, please proceed.
I guess one big PR makes sense because it's all towards that one goal and don't make that much sense otherwise, but I'm ok with either way. I'll want more explanations in the commit messages in any case (of course in a quick PoC you don't bother with that). No need to write novels, just as long as it makes it clear it's working towards the goal of using Python stable ABI and a brief explanation why that particular change is needed for the uninitiated, "because foo is not available in the stable ABI" level being quite adequate. |
Init once, dropping 3.1, and mutable type objects (the PoC uses
OK, I'll do some kind of middle ground :) |
Hey, it's been quiet on this front for quite a while. Is this a case of "too busy with other things", or is there something more to it? Just asking in case somebody else wants to pickup this work. |
Yup, too busy, mostly with a certain security issue. |
The PR is up at #2674. |
For reference, the Python version where this limitation can be lifted relatively easily is 3.10 (which adds API for type/module association, like PyType_GetModule). Later versions make it easier still. I know because I made a working proof of concept. If issues around the limitation (or reference counting, or the Python wrappers in general) come up, please let me know. |
Hello,
RPM is typically built/installed as a system component, and the Python bindings are tied to a particular minor (3.x) version of Python. Using the bindings with other Python versions is difficult.
I'd like to solve the issue for
rpm
and similar bindings to “system” packages. There's a few chicken-and-egg problems to untangle in building and installation, but I think a good first step would be building the_rpm
module with Python's Stable ABI, which means the resulting compiled module would be usable with multiple versions of Python (once copied/linked to the appropriate directory for each Python).The stable ABI requires using a limited subset of Python's C API, so it'd need some porting. I'm willing to send patches, but I would need reviews and some RPM-specific guidance.
Is this interesting in general?
If so, some details:
#ifdef
blocks._rpm
module more than once per process. This would limitrpm
's use in applications that embed Python and callPy_Initialize
/Py_Finalize
multiple times, or use sub-interpreters. AFAIK, those aren't very relevant forrpm
. I can go into details if this is an issue.The text was updated successfully, but these errors were encountered: