-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: broken dynamic import of rplugin modules #534
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`)
- Loading branch information
Showing
5 changed files
with
83 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
9 changes: 9 additions & 0 deletions
9
test/fixtures/module_plugin/rplugin/python3/mymodule/__init__.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""The `mymodule` package for the fixture module plugin.""" | ||
# pylint: disable=all | ||
|
||
# Somehow the plugin might be using relative imports. | ||
from .plugin import MyPlugin as MyPlugin | ||
|
||
# ... or absolute import (assuming this is the root package) | ||
import mymodule.plugin # noqa: I100 | ||
assert mymodule.plugin.MyPlugin is MyPlugin |
13 changes: 13 additions & 0 deletions
13
test/fixtures/module_plugin/rplugin/python3/mymodule/plugin.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Actual implement lies here.""" | ||
import pynvim as neovim | ||
import pynvim.api | ||
|
||
|
||
@neovim.plugin | ||
class MyPlugin: | ||
def __init__(self, nvim: pynvim.api.Nvim): | ||
self.nvim = nvim | ||
|
||
@neovim.command("ModuleHelloWorld") | ||
def hello_world(self) -> None: | ||
self.nvim.command("echom 'MyPlugin: Hello World!'") |
13 changes: 13 additions & 0 deletions
13
test/fixtures/simple_plugin/rplugin/python3/simple_nvim.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import neovim | ||
|
||
import pynvim.api | ||
|
||
|
||
@neovim.plugin | ||
class SimplePlugin: | ||
def __init__(self, nvim: pynvim.api.Nvim): | ||
self.nvim = nvim | ||
|
||
@neovim.command("SimpleHelloWorld") | ||
def hello_world(self) -> None: | ||
self.nvim.command("echom 'SimplePlugin: Hello World!'") |
This file contains 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