modify: auto_bind_models / global_var 支持 workers/ 进程插件路径
This commit is contained in:
@@ -430,7 +430,12 @@ def auto_bind_models(plugin_name: str):
|
||||
"""
|
||||
自动从插件 models 目录发现并绑定 Pydantic 模型
|
||||
|
||||
扫描 src/plugins/<plugin_name>/models/pydantic.py 中定义的所有模型,
|
||||
按序尝试以下模块路径(inline 插件位于 src/plugins/<name>/,
|
||||
进程插件位于 workers/<name>/):
|
||||
plugins.<name>.models.pydantic
|
||||
src.plugins.<name>.models.pydantic
|
||||
workers.<name>.models.pydantic
|
||||
|
||||
尝试按命名约定匹配已注册的 RPC 端点。
|
||||
|
||||
命名约定:
|
||||
@@ -442,17 +447,23 @@ def auto_bind_models(plugin_name: str):
|
||||
from ...decorators import auto_bind_models
|
||||
auto_bind_models("example")
|
||||
"""
|
||||
try:
|
||||
models_module = importlib.import_module(f"plugins.{plugin_name}.models.pydantic")
|
||||
except ImportError:
|
||||
for mod_name in (
|
||||
f"plugins.{plugin_name}.models.pydantic",
|
||||
f"src.plugins.{plugin_name}.models.pydantic",
|
||||
f"workers.{plugin_name}.models.pydantic",
|
||||
):
|
||||
try:
|
||||
models_module = importlib.import_module(f"src.plugins.{plugin_name}.models.pydantic")
|
||||
models_module = importlib.import_module(mod_name)
|
||||
break
|
||||
except ImportError:
|
||||
logger.warning(
|
||||
"auto_bind_models: 未找到 models 模块 (plugins.%s.models.pydantic)",
|
||||
plugin_name,
|
||||
)
|
||||
return
|
||||
models_module = None
|
||||
if models_module is None:
|
||||
logger.warning(
|
||||
"auto_bind_models: 未找到 models 模块 "
|
||||
"(plugins/src.plugins/workers 的 %s.models.pydantic)",
|
||||
plugin_name,
|
||||
)
|
||||
return
|
||||
|
||||
# 获取模块中所有 BaseModel 子类
|
||||
model_classes = {}
|
||||
|
||||
@@ -259,6 +259,7 @@ class Plugin:
|
||||
for mod in (
|
||||
f"plugins.{self.type}.global_var",
|
||||
f"src.plugins.{self.type}.global_var",
|
||||
f"workers.{self.type}.global_var",
|
||||
):
|
||||
try:
|
||||
self._gv_module = importlib.import_module(mod)
|
||||
|
||||
Reference in New Issue
Block a user