0ec9aa7e创建于 2025年12月22日历史提交
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------

import os

from common import FileOperate as f


class EnvVarName:
    def __init__(self):
        self.process_log_path = self._set_env_path("ASCEND_PROCESS_LOG_PATH")
        self.npu_collect_path = self._set_env_path("NPU_COLLECT_PATH")
        self.dump_graph_path = self._set_env_path("DUMP_GRAPH_PATH")
        self.work_path = self._set_env_path("ASCEND_WORK_PATH")
        self.cache_path = self._set_env_path("ASCEND_CACHE_PATH")
        self.opp_path = self._set_env_path("ASCEND_OPP_PATH")
        self.custom_opp_path = self._set_env_path("ASCEND_CUSTOM_OPP_PATH")
        self.current_path = os.getcwd()
        self.home_path = os.path.expanduser("~")

    @staticmethod
    def _set_env_path(env_var):
        env_path = os.getenv(env_var)
        if env_path and f.check_dir(env_path):
            ret = os.path.abspath(env_path)
        else:
            ret = None
        return ret