From 3f36be0f9f355d11ce11791744a549075609a891 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Mon, 19 Jan 2026 12:37:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(runtime):=20=E5=AE=9E=E7=8E=B0=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E6=93=8D=E4=BD=9C=E6=A8=A1=E5=9D=97=E7=9A=84?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 importlib 和 os 模块用于动态导入 - 集成 loguru 日志记录器进行错误追踪 - 实现自动遍历并导入所有子模块的逻辑 - 添加异常处理机制捕获模块加载失败的情况 - 确保所有子模块注册的算子能够正确加载 - 修复模块导入顺序以支持注解操作正常工作 --- runtime/ops/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/runtime/ops/__init__.py b/runtime/ops/__init__.py index c6e43ef..9d0c918 100644 --- a/runtime/ops/__init__.py +++ b/runtime/ops/__init__.py @@ -6,6 +6,11 @@ It is mounted into the runtime container under ``datamate.ops`` so that ``from datamate.ops.annotation...`` imports work correctly. """ +import importlib +import os + +from loguru import logger + __all__ = [ "annotation", "filter", @@ -15,3 +20,15 @@ __all__ = [ "slicer", "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}")