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 模型
|
自动从插件 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 端点。
|
尝试按命名约定匹配已注册的 RPC 端点。
|
||||||
|
|
||||||
命名约定:
|
命名约定:
|
||||||
@@ -442,14 +447,20 @@ def auto_bind_models(plugin_name: str):
|
|||||||
from ...decorators import auto_bind_models
|
from ...decorators import auto_bind_models
|
||||||
auto_bind_models("example")
|
auto_bind_models("example")
|
||||||
"""
|
"""
|
||||||
|
for mod_name in (
|
||||||
|
f"plugins.{plugin_name}.models.pydantic",
|
||||||
|
f"src.plugins.{plugin_name}.models.pydantic",
|
||||||
|
f"workers.{plugin_name}.models.pydantic",
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
models_module = importlib.import_module(f"plugins.{plugin_name}.models.pydantic")
|
models_module = importlib.import_module(mod_name)
|
||||||
except ImportError:
|
break
|
||||||
try:
|
|
||||||
models_module = importlib.import_module(f"src.plugins.{plugin_name}.models.pydantic")
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
models_module = None
|
||||||
|
if models_module is None:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"auto_bind_models: 未找到 models 模块 (plugins.%s.models.pydantic)",
|
"auto_bind_models: 未找到 models 模块 "
|
||||||
|
"(plugins/src.plugins/workers 的 %s.models.pydantic)",
|
||||||
plugin_name,
|
plugin_name,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ class Plugin:
|
|||||||
for mod in (
|
for mod in (
|
||||||
f"plugins.{self.type}.global_var",
|
f"plugins.{self.type}.global_var",
|
||||||
f"src.plugins.{self.type}.global_var",
|
f"src.plugins.{self.type}.global_var",
|
||||||
|
f"workers.{self.type}.global_var",
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
self._gv_module = importlib.import_module(mod)
|
self._gv_module = importlib.import_module(mod)
|
||||||
|
|||||||
Reference in New Issue
Block a user