build: 添加 Windows 打包方案

- 更新 PyInstaller spec 配置
- 简化 build.sh 构建脚本
- 更新 build.bat Windows 打包脚本
- 添加 docs/BUILD.md 打包说明文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
congsh
2026-02-12 15:59:23 +08:00
parent e853161975
commit 0ce1d71a90
4 changed files with 223 additions and 189 deletions

View File

@@ -1,20 +1,47 @@
# -*- mode: python ; coding: utf-8 -*-
"""
CutThenThink - Windows 打包配置
极简截图上传工具的 PyInstaller 配置
"""
import sys
from PyInstaller.building.build_main import Analysis, EXE, COLLECT, PYZ
from PyInstaller.building.api import PKG
# 项目信息
APP_NAME = 'CutThenThink'
APP_VERSION = '2.0.0'
# 分析配置
a = Analysis(
['src/main.py'],
pathex=[],
binaries=[],
datas=[('src', 'src')],
hiddenimports=['PyQt6.QtCore', 'PyQt6.QtGui', 'PyQt6.QtWidgets', 'sqlalchemy'],
datas=[
# 包含配置文件模板
('config.yaml.template', '.'),
],
hiddenimports=[
'PyQt6.QtCore',
'PyQt6.QtGui',
'PyQt6.QtWidgets',
'yaml',
],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
excludes=[
# 排除测试相关
'test',
'tests',
'pytest',
],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
# 打包配置
pyz = PYZ(a.pure, a.zipped_data, cipher=None)
exe = EXE(
pyz,
@@ -22,17 +49,42 @@ exe = EXE(
a.binaries,
a.datas,
[],
name='CutThenThink',
exclude_binaries=True,
name=APP_NAME,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx=True, # 使用 UPX 压缩
upx_exclude=[],
runtime_tmpdir=None,
console=False,
console=False, # 无控制台窗口
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=None, # TODO: 添加图标路径
)
# 收集所有文件
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name=APP_NAME,
)
# 构建 MSI 安装包Windows
pkg = PKG(
coll,
name=APP_NAME,
version=APP_VERSION,
description='极简截图上传工具',
author='CutThenThink',
keywords=['screenshot', 'upload', 'OCR'],
license='MIT',
)