Files
DataMate/runtime/ops/__init__.py
Jerry Yan 3f36be0f9f feat(runtime): 实现运行时操作模块的自动导入功能
- 添加 importlib 和 os 模块用于动态导入
- 集成 loguru 日志记录器进行错误追踪
- 实现自动遍历并导入所有子模块的逻辑
- 添加异常处理机制捕获模块加载失败的情况
- 确保所有子模块注册的算子能够正确加载
- 修复模块导入顺序以支持注解操作正常工作
2026-01-19 12:37:40 +08:00

35 lines
1002 B
Python

# -*- coding: utf-8 -*-
"""Datamate built-in operators package.
This package contains built-in operators for filtering, slicing, annotation, etc.
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",
"formatter",
"llms",
"mapper",
"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}")