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}")