-
-
Notifications
You must be signed in to change notification settings - Fork 387
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
PICARD-2751: Avoid deprecated importlib APIs, full Python 3.12 compatibility #2307
Conversation
0ea9a64
to
0e65171
Compare
Avoids use of deprecated and in Python 3.12 removed API
0e65171
to
1944a0e
Compare
FYI I just tried your PR, and it works, but I get these errors.
|
And it crashes upon changing the configuration. |
@hboetes Thanks for the feedback. The log output is quite interesting. I debugged this a bit. The plugin code gets run twice at exactly the line https://github.com/metabrainz/picard/pull/2307/files#diff-c2f162faf440349fc5556185e9cd8b4b3cf0f35235eb561eb3fd7261651a2fbfR356 . That means the
Can you elaborate? Any error output on the terminal? |
Yes, this actually happened after pressing the settings button, the first time it complains, the second time it crashes. Edit: That's a bug in the replaygain plugin, after disabling that by hacking in the config that problem is gone.
|
For the rest it seems to be working. 👍 |
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.
It looks good to me, I tested and didn't find any issue, good job!
0e98162
to
a7c9504
Compare
I have fixed the double execution in 4db506c . Essentially this happened for all plugins that themselves have relative imports. When running In the last commit I also changed a bit how plugins get loaded if they exist in multiple directories. The original implementation first tried to load from system plugin dir, but if it also existed in the user plugin dir it "unloaded" the previous plugin and loaded the new one. Now because running Overall it just shows again that we need to separate plugin metadata from code for the next plugin system. Overall I'm quite happy with how well this works now. This really should in practice work as before but using the new APIs. Also it shows that importlib provides really good interface now for us to implement plugin loading and if done properly we can for the next iteration of the plugin system simplify the loading a lot. |
d9925c0
to
6d9528c
Compare
If a plugin is already loaded avoid running its code again. This avoids double execution in case the plugin is in both the user and system plugin directory.
6d9528c
to
83ea460
Compare
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.
Overall, it looks good, just 2 minor comments
702a769
to
7d84330
Compare
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.
LGTM
Thanks for the speedy fix. One note, there are various plugins that won't work with python-3.12, like the |
@hboetes the replaygain plugin is actually supposed to work after the latest changes from this PR. At least it does so for me. Do you have any different issue now? If there is compatibility issue with one of the existing plugins we should of course fix it, but I'm currently not aware of one. |
Summary
Problem
Picard's plugin loading system must be updated to avoid long deprecated and inf Python 3.12 finally removed APIs of the importlib and zipimport modules.
This PR replaces #2134
Solution
At the core the change is to use
find_spec
in combination withexec_module
to load the modules. A large benefit is that both the normal module loading via importlib as well as the zipimporter can now use the exactly same API.Unfortunately for zipimporter we need to maintain the legacy loading code with
find_module
+load_module
for compatibility with Python < 3.10.This PR maintains full compatibility with the existing plugin systems. Overall there is likely a lot that we could further refactor and trim down, but that is something to be reserved for Picard 3.0.
To properly test the result this PR also enables CI testing with Python 3.12.0rc1