You've already forked DataMate
feat(runtime): 实现运行时操作模块的自动导入功能
- 添加 importlib 和 os 模块用于动态导入 - 集成 loguru 日志记录器进行错误追踪 - 实现自动遍历并导入所有子模块的逻辑 - 添加异常处理机制捕获模块加载失败的情况 - 确保所有子模块注册的算子能够正确加载 - 修复模块导入顺序以支持注解操作正常工作
This commit is contained in:
@@ -6,6 +6,11 @@ It is mounted into the runtime container under ``datamate.ops`` so that
|
|||||||
``from datamate.ops.annotation...`` imports work correctly.
|
``from datamate.ops.annotation...`` imports work correctly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
import os
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"annotation",
|
"annotation",
|
||||||
"filter",
|
"filter",
|
||||||
@@ -15,3 +20,15 @@ __all__ = [
|
|||||||
"slicer",
|
"slicer",
|
||||||
"user",
|
"user",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# 自动导入所有子模块以触发算子注册
|
||||||
|
current_dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
for module_name in os.listdir(current_dir):
|
||||||
|
module_path = os.path.join(current_dir, module_name)
|
||||||
|
# 检查是否是目录且包含 __init__.py
|
||||||
|
if os.path.isdir(module_path) and '__init__.py' in os.listdir(module_path):
|
||||||
|
try:
|
||||||
|
importlib.import_module(f".{module_name}", package=__name__)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to load Ops module {module_name}: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user