mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-06-07 02:45:21 +00:00
🎨 Apply black formatting
This commit is contained in:
parent
23f9a6dde4
commit
7b47606039
@ -40,15 +40,15 @@ def load_plugin(module_path: str | Path) -> Optional[Plugin]:
|
|||||||
else module_path
|
else module_path
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
module = import_module(module_path) # 导入模块对象
|
module = import_module(module_path) # 导入模块对象
|
||||||
plugin = Plugin(
|
plugin = Plugin(
|
||||||
name=module.__name__,
|
name=module.__name__,
|
||||||
module=module,
|
module=module,
|
||||||
module_name=module_path,
|
module_name=module_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
plugin.metadata = getattr(module, "__marsho_meta__", None)
|
plugin.metadata = getattr(module, "__marsho_meta__", None)
|
||||||
|
|
||||||
_plugins[plugin.name] = plugin
|
_plugins[plugin.name] = plugin
|
||||||
|
|
||||||
logger.opt(colors=True).success(
|
logger.opt(colors=True).success(
|
||||||
@ -79,15 +79,17 @@ def load_plugins(*plugin_dirs: str) -> set[Plugin]:
|
|||||||
path = Path(os.path.join(plugin_dir, f))
|
path = Path(os.path.join(plugin_dir, f))
|
||||||
|
|
||||||
module_name = None
|
module_name = None
|
||||||
|
|
||||||
if os.path.isfile(path) and f.endswith(".py"):
|
if os.path.isfile(path) and f.endswith(".py"):
|
||||||
"""单文件加载"""
|
"""单文件加载"""
|
||||||
module_name = f"{path_to_module_name(Path(plugin_dir))}.{f[:-3]}"
|
module_name = f"{path_to_module_name(Path(plugin_dir))}.{f[:-3]}"
|
||||||
|
|
||||||
elif os.path.isdir(path) and os.path.exists(os.path.join(path, "__init__.py")):
|
elif os.path.isdir(path) and os.path.exists(
|
||||||
|
os.path.join(path, "__init__.py")
|
||||||
|
):
|
||||||
"""包加载"""
|
"""包加载"""
|
||||||
module_name = path_to_module_name(path)
|
module_name = path_to_module_name(path)
|
||||||
|
|
||||||
if module_name and (plugin := load_plugin(module_name)):
|
if module_name and (plugin := load_plugin(module_name)):
|
||||||
plugins.add(plugin)
|
plugins.add(plugin)
|
||||||
return plugins
|
return plugins
|
||||||
|
@ -6,7 +6,7 @@ from pydantic import BaseModel
|
|||||||
class Plugin(BaseModel):
|
class Plugin(BaseModel):
|
||||||
"""
|
"""
|
||||||
存储插件信息
|
存储插件信息
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
----------
|
----------
|
||||||
name: str
|
name: str
|
||||||
@ -18,6 +18,7 @@ class Plugin(BaseModel):
|
|||||||
metadata: "PluginMeta" | None
|
metadata: "PluginMeta" | None
|
||||||
元
|
元
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
"""包名称 例如marsho_test"""
|
"""包名称 例如marsho_test"""
|
||||||
module: ModuleType
|
module: ModuleType
|
||||||
@ -27,6 +28,7 @@ class Plugin(BaseModel):
|
|||||||
metadata: "PluginMetadata" | None = None
|
metadata: "PluginMetadata" | None = None
|
||||||
"""元"""
|
"""元"""
|
||||||
|
|
||||||
|
|
||||||
class PluginMetadata(BaseModel):
|
class PluginMetadata(BaseModel):
|
||||||
"""
|
"""
|
||||||
Marsho 插件 对象元数据
|
Marsho 插件 对象元数据
|
||||||
@ -48,9 +50,10 @@ class PluginMetadata(BaseModel):
|
|||||||
extra: dict[str, Any]
|
extra: dict[str, Any]
|
||||||
额外信息,自定义键值对
|
额外信息,自定义键值对
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
description: str = ""
|
description: str = ""
|
||||||
usage: str = ""
|
usage: str = ""
|
||||||
author: str = ""
|
author: str = ""
|
||||||
homepage: str = ""
|
homepage: str = ""
|
||||||
extra: dict[str, Any] = {}
|
extra: dict[str, Any] = {}
|
||||||
|
@ -13,4 +13,4 @@ def path_to_module_name(path: Path) -> str:
|
|||||||
if rel_path.stem == "__init__":
|
if rel_path.stem == "__init__":
|
||||||
return ".".join(rel_path.parts[:-1])
|
return ".".join(rel_path.parts[:-1])
|
||||||
else:
|
else:
|
||||||
return ".".join(rel_path.parts[:-1] + (rel_path.stem,))
|
return ".".join(rel_path.parts[:-1] + (rel_path.stem,))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user