fix(plugin_utils): prioritize installed package import over relative cwd path in plugin loader - #2443
Closed
taran-dev4u wants to merge 1 commit into
Closed
Conversation
…cwd path in plugin loader
Documentation build overview
15 files changed ·
|
Member
|
We already opened #2419 - is this PR doing things differently or better? |
Contributor
Author
|
Hi @nhoening, thanks for pointing that out! I reviewed PR #2419 by @Flix6x — it is more comprehensive, specifically in handling namespace packages via ind_importable_package and providing full end-to-end route registration test coverage with submodules. PR #2443 was an independent exploration of #2415; since #2419 thoroughly resolves the issue, I will close this PR in favor of #2419. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2415.
Problem
In
flexmeasures/utils/plugin_utils.py,register_pluginspreviously usedif not os.path.exists(plugin)to decide whether an entry inFLEXMEASURES_PLUGINSwas an installed package or a file path.When a plugin was installed in the environment (e.g.
my_plugin), but the server was launched from a directory containing a same-named folder (my_plugin/),os.path.exists("my_plugin")returnedTrue. The loader would then re-execute__init__.pyas a fresh module object, overwritingsys.modules[plugin_name]and leaving submodules pointing to the old module object. This created an empty Blueprint during registration, causing all plugin routes to 404 and CLI groups to be empty.Solution
/,\,os.sep, absolute paths, or starting with.) from bare package names.importlib.import_module(pkg_name).ModuleNotFoundErroris raised and a local folder exists, fall back to relative path loading with an explicit warning.flexmeasures/utils/tests/test_plugin_utils.pycovering installed package prioritization, explicit file paths, fallback behavior, and error handling.