|
2 | 2 | """ |
3 | 3 |
|
4 | 4 | import subprocess |
5 | | -from pathlib import Path |
6 | 5 |
|
7 | 6 | from dev_scripts.check_funcs import ( |
8 | 7 | check_license_statement, |
|
11 | 10 | check_version_num, |
12 | 11 | ) |
13 | 12 | from dev_scripts.clear_cache import clear_pycache, clear_pyinstaller_dist |
14 | | -from dev_scripts.path_constants import ( |
15 | | - PROJECT_ROOT, |
16 | | - README_FILE_LIST, |
17 | | - RESOURCES_PATH, |
18 | | - SRC_PATH, |
19 | | -) |
20 | | - |
21 | | - |
22 | | -def process_md_images(md_file_list: list[Path]) -> None: |
23 | | - """处理 Markdown 文档中的图片链接 |
24 | | -
|
25 | | - 在构建前替换为 GitHub 图床链接,在构建后替换回本地目录中的路径 |
26 | | -
|
27 | | - :param md_file_list: Markdown 文件列表 |
28 | | - """ |
29 | | - |
30 | | - md_uri = "docs/source/images/" |
31 | | - github_uri = ( |
32 | | - "https://github.com/muziing/Py2exe-GUI/raw/main" + "/docs/source/images/" |
33 | | - ) |
34 | | - |
35 | | - for md_file in md_file_list: |
36 | | - with open(md_file, "r+", encoding="UTF-8") as f: |
37 | | - all_text = f.read() |
38 | | - if github_uri not in all_text: |
39 | | - print(f"将 {md_file} 中的本地图片路径替换为GitHub在线路径") |
40 | | - all_text_new = all_text.replace(md_uri, github_uri) |
41 | | - else: |
42 | | - print(f"将 {md_file} 中的GitHub在线路径替换为本地图片路径") |
43 | | - all_text_new = all_text.replace(github_uri, md_uri) |
44 | | - f.seek(0) |
45 | | - f.write(all_text_new) |
46 | | - # FIXME 会在文件尾部多出来莫名其妙的行 |
47 | | - |
48 | | - |
49 | | -def compile_resources() -> int: |
50 | | - """调用 RCC 工具编译静态资源 |
51 | | -
|
52 | | - :return: rcc 进程返回码 |
53 | | - """ |
54 | | - |
55 | | - compiled_file_path = RESOURCES_PATH / "COMPILED_RESOURCES.py" |
56 | | - qrc_file_path = RESOURCES_PATH / "resources.qrc" |
57 | | - cmd = [ |
58 | | - "pyside6-rcc", |
59 | | - "-o", |
60 | | - str(compiled_file_path.absolute()), |
61 | | - str(qrc_file_path.absolute()), |
62 | | - ] |
63 | | - try: |
64 | | - result = subprocess.run(cmd) |
65 | | - except subprocess.SubprocessError as e: |
66 | | - print(f"RCC编译进程错误:{e}") |
67 | | - raise e |
68 | | - else: |
69 | | - print(f"已完成静态资源文件编译,RCC返回码:{result.returncode}。") |
70 | | - return result.returncode |
| 13 | +from dev_scripts.path_constants import PROJECT_ROOT, SRC_PATH |
71 | 14 |
|
72 | 15 |
|
73 | 16 | def export_requirements() -> int: |
@@ -102,23 +45,26 @@ def build_py2exe_gui() -> None: |
102 | 45 | # 准备工作 |
103 | 46 | clear_pyinstaller_dist(SRC_PATH) |
104 | 47 | clear_pycache(SRC_PATH) |
105 | | - process_md_images(README_FILE_LIST) |
106 | 48 | # compile_resources() |
107 | 49 | export_requirements() |
108 | 50 | print(f"pre-commit 检查完毕,返回码:{check_pre_commit()}。") |
109 | 51 | print(f"mypy 检查完毕,返回码:{check_mypy()}。") |
110 | 52 |
|
111 | 53 | # 正式构建 |
112 | | - subprocess.run(["poetry", "build"]) # TODO 处理异常与返回值 |
113 | | - |
114 | | - # 清理 |
115 | | - process_md_images(README_FILE_LIST) |
| 54 | + try: |
| 55 | + result = subprocess.run(["poetry", "build"], check=True) |
| 56 | + except subprocess.SubprocessError as e: |
| 57 | + print(f"Poetry build 失败:{e}") |
| 58 | + raise |
| 59 | + else: |
| 60 | + print(f"Poetry build 完毕,返回码:{result.returncode}。") |
| 61 | + finally: |
| 62 | + # 清理 |
| 63 | + pass |
116 | 64 | else: |
117 | | - print("构建失败,有未通过的检查项") |
| 65 | + print("有未通过的检查项,不进行构建") |
118 | 66 |
|
119 | 67 |
|
120 | 68 | if __name__ == "__main__": |
121 | | - # process_md_images() |
122 | | - # compile_resources() |
123 | 69 | # export_requirements() |
124 | 70 | build_py2exe_gui() |
0 commit comments