33"""
44
55import subprocess
6- import tomllib
7- import warnings
86from pathlib import Path
97
8+ from dev_scripts .check_funcs import (
9+ check_license_statement ,
10+ check_pre_commit ,
11+ check_version_num ,
12+ )
1013from dev_scripts .clear_cache import clear_pycache , clear_pyinstaller_dist
11- from py2exe_gui import Constants
12-
13- project_root = Path ("../" ) # 项目根目录
14- src_path = project_root / "src" # 源码目录
15- resources_path = src_path / "py2exe_gui" / "Resources" # 静态资源文件目录
16- readme_file_list = [project_root / "README.md" , project_root / "README_zh.md" ]
17-
14+ from dev_scripts .path_constants import README_FILE_LIST , RESOURCES_PATH , SRC_PATH
1815
1916# TODO 加入日志模块,保存构建日志
2017
@@ -28,8 +25,7 @@ def process_md_images(md_file_list: list[Path]) -> None:
2825
2926 md_uri = "docs/source/images/"
3027 github_uri = (
31- "https://github.com/muziing/Py2exe-GUI/raw/main"
32- + "/docs/source/images/"
28+ "https://github.com/muziing/Py2exe-GUI/raw/main" + "/docs/source/images/"
3329 )
3430
3531 for md_file in md_file_list :
@@ -46,58 +42,14 @@ def process_md_images(md_file_list: list[Path]) -> None:
4642 # FIXME 会在文件尾部多出来莫名其妙的行
4743
4844
49- def check_version_num () -> bool :
50- """
51- 检查各部分声明的版本号是否一致 \n
52- """
53-
54- print ("正在检查各处版本号是否一致..." )
55-
56- app_constant_version = Constants .app_constants .AppConstant .VERSION
57- with open (project_root / "pyproject.toml" , "rb" ) as ppj_toml_file :
58- ppj_dict = tomllib .load (ppj_toml_file )
59- ppj_version = ppj_dict ["tool" ]["poetry" ]["version" ]
60-
61- if ppj_version == app_constant_version :
62- print (f"版本号检查完毕,均为 { ppj_version } 。" )
63- return True
64- else :
65- warning_mes = (
66- """版本号不一致!\n """
67- + f"""pyproject.toml................{ ppj_version } \n """
68- + f"""Constants.AppConstant.........{ app_constant_version } \n """
69- )
70- warnings .warn (warning_mes , stacklevel = 1 )
71- return False
72-
73-
74- def pre_commit_check () -> int :
75- """
76- 调用已有的 pre-commit 检查工具进行检查 \n
77- :return: pre-commit 进程返回码
78- """
79-
80- pre_commit_run_cmd = ["pre-commit" , "run" , "--all-files" ]
81- print ("开始进行第一次 pre-commit 检查:" )
82- result_1 = subprocess .run (pre_commit_run_cmd )
83- if result_1 .returncode != 0 :
84- print ("开始进行第二次 pre-commit 检查:" )
85- result_2 = subprocess .run (pre_commit_run_cmd )
86- if result_2 .returncode != 0 :
87- warnings .warn ("pre-commit进程返回码非0,建议检查" , stacklevel = 1 )
88- return result_2 .returncode
89- else :
90- return 0
91-
92-
9345def compile_resources () -> int :
9446 """
9547 调用 RCC 工具编译静态资源 \n
9648 :return: rcc 进程返回码
9749 """
9850
99- compiled_file_path = resources_path / "compiled_resources.py"
100- qrc_file_path = resources_path / "resources.qrc"
51+ compiled_file_path = RESOURCES_PATH / "compiled_resources.py"
52+ qrc_file_path = RESOURCES_PATH / "resources.qrc"
10153 cmd = [
10254 "pyside6-rcc" ,
10355 "-o" ,
@@ -114,26 +66,24 @@ def build_py2exe_gui() -> None:
11466 构建项目的总函数 \n
11567 """
11668
117- if check_version_num ():
69+ if check_version_num () + check_license_statement () == 0 :
11870 # 准备工作
119- clear_pyinstaller_dist (src_path )
120- clear_pycache (src_path )
121- process_md_images (readme_file_list )
71+ clear_pyinstaller_dist (SRC_PATH )
72+ clear_pycache (SRC_PATH )
73+ process_md_images (README_FILE_LIST )
12274 # compile_resources()
123- print (f"pre-commit检查完毕,返回码:{ pre_commit_check ()} 。" )
75+ print (f"pre-commit检查完毕,返回码:{ check_pre_commit ()} 。" )
12476
12577 # 正式构建
12678 subprocess .run (["poetry" , "build" ]) # TODO 处理异常与返回值
12779
12880 # 清理
129- process_md_images (readme_file_list )
81+ process_md_images (README_FILE_LIST )
13082 else :
13183 print ("构建失败,有未通过的检查项" )
13284
13385
13486if __name__ == "__main__" :
135- # check_version_num()
136- # print(pre_commit_check())
13787 # compile_resources()
13888 # process_md_images()
13989 build_py2exe_gui ()
0 commit comments