Skip to content
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

[#1462] Remove Deprecated load_module() Function #2217

Merged

Conversation

Rixxan
Copy link
Contributor

@Rixxan Rixxan commented May 1, 2024

Description

importlib's load_module() function has been deprecated since Python 3.4, and has been toyed with being removed in the past. To replace it, the importlib exec_module() function has been introduced as a more "modern" method of importing modules, such as plugins.

This is not a drop-in replacement, however. Some work needs to be done to resolve issues with some plugins and imports, particularly more complicated plugins which use dataclasses, decorators, and other more advanced functions. Previous attempts (such as 816d041) tried to simply work around this, however were not granular enough to suffice.

This fixes a bug with the last attempt at fixing this issue by ensuring that sys.modules is aware of the imported module and can process it correctly in its namespace. Only once this is done does the program attempt to load the plugin. This also adds additional error checking and validation to ensure that a valid plugin is being sent to the program.

This will remove one of the major blocking events for us to move to Python 3.12 or beyond.,

Type of Change

  • Feature Enhancement

How Tested

Tested on a number of third party and bundled plugins, including:

  • DistanceCalc
  • EDMC-Canonn 7.3.1
  • EDMC-Canonn 7.3.2
  • HabZone-master (to ensure Plugins without Python 3 support still don't load)
  • HuttonHelper 3.0.4
  • Norohind's Spanch Router
  • EDMC PluginTest

Notes

The previous attempt was almost correct - but we needed to ensure that the system was aware of the module in order to handle it correctly. Additional testing of 3rd party plugins to ensure no plugins break with this is recommended.

Resolves #1462

The previous attempt was almost correct - but we needed to ensure that the system was aware of the module in order to handle it correctly.
@Rixxan Rixxan added enhancement help wanted Plugins Anything related to plugins python Pull requests that update Python code Ready for Review PRs ready for review and merge labels May 1, 2024
@Rixxan Rixxan added this to the 5.11.0 milestone May 1, 2024
@Rixxan Rixxan self-assigned this May 1, 2024
plug.py Outdated Show resolved Hide resolved
Add Slightly More Useful Comment
@Rixxan Rixxan linked an issue May 6, 2024 that may be closed by this pull request
Copy link
Member

@C1701D C1701D left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with multiple plugins, none broke, LGTM.

@Rixxan Rixxan merged commit 2d58ef9 into EDCD:develop May 24, 2024
3 checks passed
@Rixxan Rixxan deleted the enhancement/1462/loadmodule-replacement branch May 24, 2024 22:39
@Athanasius
Copy link
Contributor

Tested with multiple plugins, none broke, LGTM.

Just to be sure... that selection of plugins definitely covered the ones that both provide and make use of a module themselves, right ? edmcoverlay is one such, but I've no direct experience with it myself. I think perhaps it, and some other plugins only have a top-level __init__.py in order to 'hack' them being earlier in the load order.

I'm struggling to find any other actual examples. The idea is that some plugins might (also) provide a library for use by other plugins. Was that case tested ? Although, tbh, if it's that rare, I'd want to check they worked as intended on the old loading code as well....

@Rixxan Rixxan added the Staged Feature Complete and in Testing for Next Release label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted Plugins Anything related to plugins python Pull requests that update Python code Ready for Review PRs ready for review and merge Staged Feature Complete and in Testing for Next Release
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

load_module() being deprecated for Python 3.12
3 participants