From 4fcc755cb8520a40c913c2a3f422d7d14f5a8f14 Mon Sep 17 00:00:00 2001 From: pxp1 <958876660@qq.com> Date: Thu, 29 Aug 2024 17:34:53 +0800 Subject: [PATCH] =?UTF-8?q?code=20checker=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- config_checking/checkers/base_checker.py | 2 +- config_checking/checkers/code_checker.py | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b4b6144..522bf23 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ ``` { - "training root path": "str", # 训练代码根目录 + "code path": "str", # 训练代码根目录 "exec cmd filepath": "str", # 启动命令所在文件 "config_home_dirs": "dict", # 多个配置文件路径 "ckpt path": "str", # checkpoint所在路径 diff --git a/config_checking/checkers/base_checker.py b/config_checking/checkers/base_checker.py index e7e44c4..6cc2da6 100644 --- a/config_checking/checkers/base_checker.py +++ b/config_checking/checkers/base_checker.py @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod class PackInput: def __init__(self, config_dict=None, model=None): - self.training_root_path = config_dict.get("training root path", None) + self.code_path = config_dict.get("code path", None) self.exec_cmd_filepath = config_dict.get("exec cmd filepath", None) self.config_home_dirs = config_dict.get("config_home_dirs", None) self.ckpt_path = config_dict.get("ckpt path", None) diff --git a/config_checking/checkers/code_checker.py b/config_checking/checkers/code_checker.py index 60b145b..71da0a3 100644 --- a/config_checking/checkers/code_checker.py +++ b/config_checking/checkers/code_checker.py @@ -2,7 +2,7 @@ import os from config_checking.utils.dir_cmp import compare_directories from config_checking.checkers.base_checker import BaseChecker -from config_checking.utils.packing import DirPacker +from config_checking.utils.packing import DirPacker, add_file_to_zip from config_checking.config_checker import register_checker_item from config_checking.utils.utils import write_list_to_file @@ -33,18 +33,23 @@ def file_suffix_to_label(filepaths): @register_checker_item("code") class CodeChecker(BaseChecker): - input_needed = "training_root_path" + input_needed = "code_path" target_name_in_zip = "code" result_dirname = "code" result_filename = "code_change_summary.txt" def pack(pack_input): - training_dir = pack_input.training_root_path + code_path = pack_input.code_path output_zip_path = pack_input.output_zip_path - if os.path.isdir(training_dir): - DirPacker(training_dir, output_zip_path, CodeChecker.target_name_in_zip) - print(f"add source code dir {training_dir} to zip") + if os.path.isdir(code_path): + DirPacker(code_path, output_zip_path, CodeChecker.target_name_in_zip) + print(f"add code dir {code_path} to zip") + elif os.path.isfile(code_path): + dest_path_in_zip = os.path.join(CodeChecker.target_name_in_zip, os.path.basename(code_path)) + add_file_to_zip(output_zip_path, code_path, dest_path_in_zip) + print(f"add code file {code_path} to zip") + def compare(bench_dir, cmp_dir, output_path): bench_code_dir = os.path.join(bench_dir, CodeChecker.target_name_in_zip) -- Gitee