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

17 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# Copyright (c) 2026 Huawei Technologies Co., Ltd. 

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

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

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

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

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

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

11# ----------------------------------------------------------------------------------------------------------- 

12 

13"""Python pass artifact discovery helpers.""" 

14 

15from __future__ import annotations 

16 

17from pathlib import Path 

18from types import ModuleType 

19from typing import Iterable, Optional 

20 

21from ge._internal.artifact_utils import ( 

22 PythonArtifact, 

23 find_compatible_artifact, 

24 iter_artifacts as iter_artifacts_from_root, 

25 load_bridge_artifact_manifest, 

26 load_module_from_path, 

27) 

28 

29BRIDGE_ABI_VERSION = 1 

30NATIVE_MODULE_NAME = "ge.passes._ge_pass_native" 

31 

32 

33def artifacts_root() -> Path: 

34 return Path(__file__).resolve().parent / "python_pass_artifacts" 

35 

36 

37def load_artifact_from_dir(artifact_dir: Path) -> Optional[PythonArtifact]: 

38 return load_bridge_artifact_manifest(artifact_dir / "manifest.json") 

39 

40 

41def iter_artifacts(root: Optional[Path] = None) -> Iterable[PythonArtifact]: 

42 return iter_artifacts_from_root( 

43 root or artifacts_root(), load_bridge_artifact_manifest 

44 ) 

45 

46 

47def find_prebuilt_artifact() -> Optional[PythonArtifact]: 

48 return find_compatible_artifact(iter_artifacts(), BRIDGE_ABI_VERSION) 

49 

50 

51def load_native_module(native_path: Path) -> ModuleType: 

52 return load_module_from_path(NATIVE_MODULE_NAME, native_path)