2023-12-29 16:13:12 +08:00
|
|
|
|
"""用于构建项目的脚本
|
2023-11-12 20:54:01 +08:00
|
|
|
|
"""
|
|
|
|
|
|
2024-01-06 12:00:00 +08:00
|
|
|
|
__all__ = [
|
|
|
|
|
"export_requirements",
|
|
|
|
|
"build_py2exe_gui",
|
|
|
|
|
]
|
|
|
|
|
|
2023-11-12 20:54:01 +08:00
|
|
|
|
import subprocess
|
|
|
|
|
|
2023-12-04 21:54:06 +08:00
|
|
|
|
from dev_scripts.check_funcs import (
|
|
|
|
|
check_license_statement,
|
2023-12-09 16:57:12 +08:00
|
|
|
|
check_mypy,
|
2023-12-04 21:54:06 +08:00
|
|
|
|
check_pre_commit,
|
|
|
|
|
check_version_num,
|
|
|
|
|
)
|
2023-11-12 20:54:01 +08:00
|
|
|
|
from dev_scripts.clear_cache import clear_pycache, clear_pyinstaller_dist
|
2024-01-04 21:59:23 +08:00
|
|
|
|
from dev_scripts.path_constants import PROJECT_ROOT, SRC_PATH
|
2023-11-12 20:54:01 +08:00
|
|
|
|
|
|
|
|
|
|
2023-12-13 16:34:59 +08:00
|
|
|
|
def export_requirements() -> int:
|
2023-12-29 16:13:12 +08:00
|
|
|
|
"""将项目依赖项导出至 requirements.txt 中
|
|
|
|
|
|
2023-12-13 16:34:59 +08:00
|
|
|
|
:return: poetry export 命令返回值
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
poetry_export_cmd = [
|
|
|
|
|
"poetry",
|
|
|
|
|
"export",
|
|
|
|
|
"--without-hashes",
|
|
|
|
|
"-o",
|
|
|
|
|
PROJECT_ROOT / "requirements.txt",
|
|
|
|
|
"--format=requirements.txt",
|
|
|
|
|
]
|
2023-12-29 16:13:12 +08:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
result = subprocess.run(poetry_export_cmd)
|
|
|
|
|
except subprocess.SubprocessError as e:
|
|
|
|
|
print(f"poetry export 进程错误:{e}")
|
|
|
|
|
raise e
|
|
|
|
|
else:
|
|
|
|
|
print(f"已将当前项目依赖导出至 requirements.txt,poetry export 返回码:{result.returncode}")
|
|
|
|
|
return result.returncode
|
2023-12-13 16:34:59 +08:00
|
|
|
|
|
|
|
|
|
|
2023-11-12 20:54:01 +08:00
|
|
|
|
def build_py2exe_gui() -> None:
|
2023-12-29 16:13:12 +08:00
|
|
|
|
"""构建项目的总函数"""
|
2023-11-12 20:54:01 +08:00
|
|
|
|
|
2023-12-04 21:54:06 +08:00
|
|
|
|
if check_version_num() + check_license_statement() == 0:
|
2023-11-12 20:54:01 +08:00
|
|
|
|
# 准备工作
|
2023-12-04 21:54:06 +08:00
|
|
|
|
clear_pyinstaller_dist(SRC_PATH)
|
|
|
|
|
clear_pycache(SRC_PATH)
|
2023-11-12 22:01:28 +08:00
|
|
|
|
# compile_resources()
|
2024-01-06 12:00:00 +08:00
|
|
|
|
# export_requirements()
|
2023-12-09 16:57:12 +08:00
|
|
|
|
print(f"pre-commit 检查完毕,返回码:{check_pre_commit()}。")
|
|
|
|
|
print(f"mypy 检查完毕,返回码:{check_mypy()}。")
|
2023-11-12 20:54:01 +08:00
|
|
|
|
|
|
|
|
|
# 正式构建
|
2024-01-04 14:47:15 +08:00
|
|
|
|
try:
|
|
|
|
|
result = subprocess.run(["poetry", "build"], check=True)
|
|
|
|
|
except subprocess.SubprocessError as e:
|
|
|
|
|
print(f"Poetry build 失败:{e}")
|
|
|
|
|
raise
|
|
|
|
|
else:
|
|
|
|
|
print(f"Poetry build 完毕,返回码:{result.returncode}。")
|
|
|
|
|
finally:
|
|
|
|
|
# 清理
|
2024-01-04 21:59:23 +08:00
|
|
|
|
pass
|
2023-11-12 20:54:01 +08:00
|
|
|
|
else:
|
2024-01-04 14:47:15 +08:00
|
|
|
|
print("有未通过的检查项,不进行构建")
|
2023-11-12 20:54:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-12-13 16:34:59 +08:00
|
|
|
|
# export_requirements()
|
2023-11-12 20:54:01 +08:00
|
|
|
|
build_py2exe_gui()
|