Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/dttest/api/python/ge/ge/es/__init__.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-27 10:03 +0800

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3# ------------------------------------------------------------------- 

4# ----------------------------------------------------------------------------------------------------------- 

5# Copyright (c) 2025 Huawei Technologies Co., Ltd. 

6# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 

7# CANN Open Software License Agreement Version 2.0 (the "License"). 

8# Please refer to the License for details. You may not use this file except in compliance with the License. 

9# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 

10# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. 

11# See LICENSE in the root of the software repository for the full text of the License. 

12# ----------------------------------------------------------------------------------------------------------- 

13 

14""" 

15es - eager style构图基础组件 

16 

17这个模块提供了图构建基础组件的Python封装,包括: 

18- GraphBuilder: 图构建器对象 

19- TensorHolder: 张量持有者对象 

20- list_plugins: 列出所有已加载的插件名称 

21- get_plugin: 获取指定名称的插件模块 

22 

23同时支持通过 entry_points 机制自动加载插件包(如 es_math、es_nn 等)。 

24""" 

25 

26__all__ = ["GraphBuilder", "TensorHolder", "list_plugins", "get_plugin"] 

27 

28from types import ModuleType 

29from typing import List, Union 

30 

31from ._plugin_loader import load_all_plugins 

32from .graph_builder import GraphBuilder 

33from .tensor_holder import TensorHolder 

34 

35# 加载所有已注册的插件 

36_plugins = load_all_plugins() 

37# 动态挂载插件到当前命名空间 

38for name, module in _plugins.items(): 

39 globals()[name] = module 

40 __all__.append(name) 

41 

42 

43def list_plugins() -> List[str]: 

44 """ 

45 List all loaded plugin names. 

46 

47 Returns: 

48 list: List of plugin names 

49 """ 

50 return list(_plugins.keys()) 

51 

52 

53def get_plugin(plugin_name: str) -> Union[ModuleType, None]: 

54 """ 

55 Get the plugin module with the specified name. 

56 

57 Args: 

58 plugin_name (str): Plugin name (e.g., 'math', 'nn') 

59 

60 Returns: 

61 module: Plugin module object, or None if not found 

62 """ 

63 return _plugins.get(plugin_name)