Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/dttest/api/python/ge/ge/pyatc/__main__.py: 95%

22 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-27 10:02 +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"""pyatc CLI entry point.""" 

14 

15import ctypes 

16import os 

17import sys 

18 

19from ge._capi.pypyatc_wrapper import pyatc_lib 

20 

21 

22def _build_native_argv(argv): 

23 encoded = [arg.encode("utf-8") for arg in argv] 

24 c_argv = (ctypes.c_char_p * len(encoded))(*encoded) 

25 return encoded, c_argv 

26 

27 

28def _build_native_cmdline_argv(cmdline_argv0=None, args=None): 

29 if cmdline_argv0 is not None: 

30 return [cmdline_argv0] + list(args or []) 

31 

32 native_argv = list(sys.argv) 

33 if native_argv and os.path.basename(native_argv[0]) == "__main__.py": 

34 native_argv[0] = sys.executable + " -m ge.pyatc" 

35 return native_argv 

36 

37 

38def main(cmdline_argv0=None, args=None) -> None: 

39 native_argv = _build_native_cmdline_argv(cmdline_argv0, args) 

40 encoded, c_argv = _build_native_argv(native_argv) 

41 ret = pyatc_lib.GeApiWrapper_Atc_Main(len(c_argv), c_argv) 

42 sys.exit(ret) 

43 

44 

45if __name__ == "__main__": 

46 main()