-
Notifications
You must be signed in to change notification settings - Fork 4
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
Automatically import binary extensions whose suffixes include the python version #15
Conversation
Build failed. ❌ pre-commit FAILURE in 1m 27s |
Build failed. ❌ pre-commit FAILURE in 1m 32s |
Build failed. ❌ pre-commit FAILURE in 1m 25s |
Build failed. ❌ pre-commit FAILURE in 1m 27s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 29s |
5c48547
to
a20dfcc
Compare
Build succeeded. ✔️ pre-commit SUCCESS in 1m 29s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 27s |
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.
Thanks, this looks interesting!
I left some comments. It would be also nice to have some test cases for this.
Thanks for the feedback! Going through it now. I'm happy to add testcases if this is ultimately seen as viable |
Build failed. ❌ pre-commit FAILURE in 1m 31s |
Ok, I reworked this to just loop through
|
Build succeeded. ✔️ pre-commit SUCCESS in 1m 35s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 33s |
While this is more straightforward, I think I liked the previous solution better. Doing it this way it could attempt to load unnecessary modules and that could cause problems, I can imagine a situation where in an unversioned sitepackages path (I think Debian/Ubuntu use those) there are binary modules in multiple versions and loading all of them would be impossible. Getting module name from the exception and constructing filename by trying valid suffixes seems like a better way. |
yeah, definitely a drawback to this method. The alternative, I think, would be to do something like reload() in a loop, and break when either:
If that sounds good (or if there's a better way) I'm happy to go with it. |
Yes, that's what I had in mind - loop until there are no more recoverable |
Alright, super! Working on it now |
Build failed. ❌ pre-commit FAILURE in 1m 38s |
Build failed. ❌ pre-commit FAILURE in 1m 33s |
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.
These are all style suggestions, the code looks fine 👍
Alright, thanks for the feedback! I've taken all the suggested changes now |
Build failed. ❌ pre-commit FAILURE in 1m 33s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 33s |
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.
Great, thanks. Only some test cases are missing, but I'll try to come up with some, unless you want to do it yourself.
Could you please squash the commits into one?
Alright, thanks so much for your review and feedback. I love this little shim and I'm so happy to be able to contribute. As an internet rando, I don't actually have write access, so I can't do the merge step myself.
I'm not familiar with your test framework, but I can think of a few basic designs. The obvious one is the positive test case, on rhel9, install python3.11, create a virtualenv, then But seems like it might be good to have some negative test cases:
|
I will merge the PR once you squash the commits into one (or more if you feel that's necessary, but I think one is fine). Also, could you please follow the guidelines when doing it? 🙂
There isn't really any framework, just a script that imports
Yes, that's what I had in mind, and it shouldn't be diffcult to modify existing test case to install and run Python 3.11.
Nice idea. |
sure, will do!
Ok, I'm happy to write tests. Just looking through the workflow now, the same test is run on all flavors of linux. How would you approach adding a test that only runs on one of them? |
Thanks!
There could be another environment variable that would be passed to the container and the scripts would react accordingly. Though technically for the simplest case of installing and running in Python 3.11 on RHEL9 (ubi9) it can be simply added to Actually, even the removal of binary modules could be done in |
54b6a16
to
b3c25d4
Compare
Build succeeded. ✔️ pre-commit SUCCESS in 1m 37s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 26s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 25s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 25s |
7fcaee7
to
bbe85f4
Compare
Build succeeded. ✔️ pre-commit SUCCESS in 1m 40s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 26s |
b8ff96f
to
180dfd1
Compare
Build succeeded. ✔️ pre-commit SUCCESS in 1m 35s |
Ok, I have this squashed and a couple scenarios added. Unfortunately (or really, fortunately) the scenario I set up with python36 reveals an issue.
Nothing is raised, so nothing is caught, and then nothing is helped. |
Excellent, thanks. The commit message title is a bit long, but that's ok. It shouldn't end with a dot though.
Ok, it's a bit hackish, but I suppose we could do something like |
Yeah, and this is still an improvement, since none of the existing python-rpm versions require this. All old versions include the unversioned .so files, and all new versions have just one extension, _rpm, which works. But still, it's agonizing to be so close to a robust solution and then have to settle. One thing I toyed with was modifying
So you could use that to load _rpmb and _rpms dynamically. But you would have to assume that all modules should be imported. It's really too bad the actual loader machinery doesn't care what's in EXTENSION_SUFFIXES. If it did, we'd be home free. It's clear python just does not want you to use anything but native suffixes, haha. |
180dfd1
to
c06a940
Compare
Build succeeded. ✔️ pre-commit SUCCESS in 1m 31s |
Ok, let me merge this. Thanks again for your contribution. |
Build succeeded (gate pipeline). ✔️ pre-commit SUCCESS in 1m 25s |
Pull request merge failed: Resource not accessible by integration, You may need to manually rebase your PR and retry. |
My pleasure, thank you so much for taking this change, and for walking me through your process |
TODO:
packit/packit.dev
.For an edge case where the current interpreter version differs from that of the rpm library, and where that library's extension suffixes are included in the
_rpm.so
filename (e.g._rpm.cpython-39-x86_64-linux-gnu.so
on RHEL 9.x), add a newreload_module
method that finds the matching .so and imports it directly.The basic operation is:
importlib.machinery.EXTENSION_SUFFIXES
ModuleNotFoundError
ModuleNotFoundError
, loop through the suffix list, looking for a matching{module}.{suffix}.so
on diskrpm.{module}
directly by pathThis is probably naive or unwise in some way, but I wanted to take a stab at it so I can use rpm-shim in on RHEL 9.x systems at my company without needing to use the
sudo ln
workaroundExample from python3.11 on el9 (Oracle 9.x):