mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 09:05:04 +08:00
commit
a14cfc8d77
@ -10,8 +10,8 @@ from typing import Set, Dict, List, Union, Iterable, Optional, Sequence
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.utils import escape_tag
|
||||
from .plugin import Plugin, _new_plugin
|
||||
from . import _managers, _current_plugin
|
||||
from .plugin import Plugin, _new_plugin, _confirm_plugin
|
||||
|
||||
|
||||
class PluginManager:
|
||||
@ -180,6 +180,8 @@ class PluginLoader(SourceFileLoader):
|
||||
# ) from e
|
||||
super().exec_module(module)
|
||||
|
||||
_confirm_plugin(plugin)
|
||||
|
||||
_current_plugin.reset(_plugin_token)
|
||||
return
|
||||
|
||||
|
@ -96,5 +96,10 @@ def _new_plugin(fullname: str, module: ModuleType, manager: "PluginManager") ->
|
||||
if name in plugins:
|
||||
raise RuntimeError("Plugin already exists! Check your plugin name.")
|
||||
plugin = Plugin(name, module, fullname, manager)
|
||||
plugins[name] = plugin
|
||||
return plugin
|
||||
|
||||
|
||||
def _confirm_plugin(plugin: Plugin) -> None:
|
||||
if plugin.name in plugins:
|
||||
raise RuntimeError("Plugin already exists! Check your plugin name.")
|
||||
plugins[plugin.name] = plugin
|
||||
|
@ -94,3 +94,9 @@ async def test_load_plugin(load_plugin: Set["Plugin"]):
|
||||
assert False
|
||||
except RuntimeError:
|
||||
assert True
|
||||
|
||||
try:
|
||||
nonebot.load_plugin("some_plugin_no_exist")
|
||||
assert False
|
||||
except Exception:
|
||||
assert nonebot.get_plugin("some_plugin_no_exist") is None
|
||||
|
Loading…
Reference in New Issue
Block a user