-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathapp.spec
More file actions
129 lines (114 loc) · 3.02 KB
/
app.spec
File metadata and controls
129 lines (114 loc) · 3.02 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# -*- mode: python ; coding: utf-8 -*-
import sys
from pathlib import Path
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
block_cipher = None
# 读取版本信息
VERSION = Path('VERSION').read_text().strip()
# 应用名称
app_name = '电商图片AI处理工具'
# 图标路径配置
icon_dir = Path('resources/icons')
if sys.platform == 'darwin':
icon_path = icon_dir / 'icon.icns' if (icon_dir / 'icon.icns').exists() else None
elif sys.platform == 'win32':
icon_path = icon_dir / 'icon.ico' if (icon_dir / 'icon.ico').exists() else None
else: # Linux
icon_path = icon_dir / 'icon.png' if (icon_dir / 'icon.png').exists() else None
# 数据文件
datas = [
('src/ui/resources', 'src/ui/resources'), # UI 资源文件
('VERSION', '.'), # 版本文件
]
# 添加 Qt 插件和资源
try:
qt_datas = collect_data_files('PyQt6.Qt6', subdir='plugins')
datas.extend(qt_datas)
except Exception:
pass
# 隐藏导入(确保所有依赖被包含)
hiddenimports = [
'PyQt6.QtCore',
'PyQt6.QtGui',
'PyQt6.QtWidgets',
'PyQt6.sip',
'PIL._tkinter_finder',
'keyring.backends',
'keyring.backends.macOS', # macOS
'keyring.backends.Windows', # Windows
'keyring.backends.SecretService', # Linux
]
# 添加 Qt 子模块
try:
qt_hidden = collect_submodules('PyQt6')
hiddenimports.extend([m for m in qt_hidden if m not in hiddenimports])
except Exception:
pass
# 排除的模块(减小打包体积)
excludes = [
'matplotlib',
'numpy',
'pandas',
'scipy',
'pytest',
'tkinter',
]
a = Analysis(
['src/main.py'],
pathex=[],
binaries=[],
datas=datas,
hiddenimports=hiddenimports,
hookspath=['hooks'],
hooksconfig={},
runtime_hooks=['hooks/runtime_hook_pyqt6.py'],
excludes=excludes,
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name=app_name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False, # 不显示控制台窗口
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=str(icon_path) if icon_path else None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name=app_name,
)
# macOS 应用包配置
if sys.platform == 'darwin':
app = BUNDLE(
coll,
name=f'{app_name}.app',
icon=str(icon_path) if icon_path and icon_path.suffix == '.icns' else None,
bundle_identifier='io.jiuling.ecommerce-image-processor',
version=VERSION,
info_plist={
'NSPrincipalClass': 'NSApplication',
'NSHighResolutionCapable': 'True',
'CFBundleShortVersionString': VERSION,
'CFBundleVersion': VERSION,
},
)