100600bfbSopenharmony_ci#!/usr/bin/env python3 200600bfbSopenharmony_ci# -*- coding: utf-8 -*- 300600bfbSopenharmony_ci# Copyright (C) 2024 Huawei Device Co., Ltd. 400600bfbSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 500600bfbSopenharmony_ci# you may not use this file except in compliance with the License. 600600bfbSopenharmony_ci# You may obtain a copy of the License at 700600bfbSopenharmony_ci# 800600bfbSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 900600bfbSopenharmony_ci# 1000600bfbSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1100600bfbSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1200600bfbSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1300600bfbSopenharmony_ci# See the License for the specific language governing permissions and 1400600bfbSopenharmony_ci# limitations under the License. 1500600bfbSopenharmony_ci 1600600bfbSopenharmony_ciimport subprocess 1700600bfbSopenharmony_ci 1800600bfbSopenharmony_ci# 自动安装依赖 1900600bfbSopenharmony_cidef install_dependencies(requirements_file): 2000600bfbSopenharmony_ci try: 2100600bfbSopenharmony_ci subprocess.check_call(["pip", "install", "-r", requirements_file]) 2200600bfbSopenharmony_ci print(f"install requirements.txt success") 2300600bfbSopenharmony_ci except subprocess.CalledProcessError as e: 2400600bfbSopenharmony_ci print(f"install dependence fail: {str(e)}") 2500600bfbSopenharmony_ci 2600600bfbSopenharmony_ci# # 自动生成依赖文件 2700600bfbSopenharmony_ci# def generate_requirements_file(output_file): 2800600bfbSopenharmony_ci# try: 2900600bfbSopenharmony_ci# subprocess.check_call(["pip", "freeze"], text=True, stdout=open(output_file, 'w')) 3000600bfbSopenharmony_ci# except subprocess.CalledProcessError as e: 3100600bfbSopenharmony_ci# print(f"生成requirements.txt失败: {str(e)}") 3200600bfbSopenharmony_ci 3300600bfbSopenharmony_ci# 使用方法 3400600bfbSopenharmony_ci# generate_requirements_file("requirements.txt") 3500600bfbSopenharmony_ciinstall_dependencies("requirements.txt")