-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
69 lines (55 loc) · 1.66 KB
/
Copy pathbuild.py
File metadata and controls
69 lines (55 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""PatchTool 打包脚本 - 将项目打包为单文件 exe"""
import os
import shutil
import subprocess
import sys
# 项目根目录
ROOT = os.path.dirname(os.path.abspath(__file__))
DIST_DIR = os.path.join(ROOT, "dist")
BUILD_DIR = os.path.join(ROOT, "build_temp")
SPEC_FILE = os.path.join(ROOT, "build.spec")
OUTPUT_EXE = os.path.join(DIST_DIR, "PatchTool.exe")
def check_pyinstaller():
try:
import PyInstaller
print(f"PyInstaller {PyInstaller.__version__} 已就绪")
return True
except ImportError:
print("未安装 PyInstaller,正在安装...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "pyinstaller"])
print("PyInstaller 安装完成")
return True
def clean():
for d in [BUILD_DIR, DIST_DIR]:
if os.path.exists(d):
shutil.rmtree(d)
print(f"已清理: {d}")
def build():
cmd = [
sys.executable, "-m", "PyInstaller",
SPEC_FILE,
"--distpath", DIST_DIR,
"--workpath", BUILD_DIR,
"--clean", "-y",
]
print(f"执行: {' '.join(cmd)}\n")
subprocess.check_call(cmd, cwd=ROOT)
def main():
print("=" * 50)
print(" PatchTool 打包脚本")
print("=" * 50)
check_pyinstaller()
clean()
build()
if os.path.isfile(OUTPUT_EXE):
size_mb = os.path.getsize(OUTPUT_EXE) / (1024 * 1024)
print("\n" + "=" * 50)
print(f" 打包成功!")
print(f" 输出: {OUTPUT_EXE}")
print(f" 大小: {size_mb:.1f} MB")
print("=" * 50)
else:
print("\n打包失败,未找到输出文件")
sys.exit(1)
if __name__ == "__main__":
main()