fix: fix broken dynamic import of rplugin modules #534
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.
The removal of
imp
package (#461) in order to supprot Python 3.12 had a bug where rplugins can't be loaded and the ImportError exception was silenced, making the remote provider throwing lots of errors. This commit fixes broken dynamic import of python modules from the registered rplugins.We add tests for Host._load, with loading rplugins consisting of:
(1) single-file module (e.g.,
rplugins/simple_plugin.py
)(2) package (e.g.,
rplugins/mymodule/__init__.py
)Note: As per https://docs.python.org/3.12/whatsnew/3.12.html#imp, I also tried something like:
but this fails to resolve relative import within the package to unlike the previous implementation using
imp
(see the unit test fixtures). Possible more addition ofloader
would be needed. If you think this is the right way, please let me know so we can have additional work. Actually the remote host python should be able to import packages, so I don't see any reason why we couldn't use the approach of manipulatingsys.path
and import the module.