-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathripperdoc.spec
More file actions
231 lines (208 loc) · 5.27 KB
/
ripperdoc.spec
File metadata and controls
231 lines (208 loc) · 5.27 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# -*- mode: python ; coding: utf-8 -*-
"""
Ripperdoc PyInstaller Spec File
使用方法:
# 单文件模式 (默认)
pyinstaller ripperdoc.spec
# 目录模式 (推荐,支持外部数据文件)
pyinstaller ripperdoc.spec --onedir
或使用构建脚本:
python scripts/build.py # 单文件模式
python scripts/build.py --dir # 目录模式
"""
import os
import sys
from pathlib import Path
from importlib.util import find_spec
from PyInstaller.utils.hooks import collect_submodules
# 构建模式: 'onefile' (单文件) 或 'onedir' (目录)
# 可以通过 --onedir 参数覆盖,或在此处修改默认值
BUILD_MODE = os.environ.get("RIPPERDOC_BUILD_MODE", "onedir")
# 项目根目录
ROOT_DIR = Path(SPECPATH).parent
# 数据文件目录
DATA_DIR = ROOT_DIR / "ripperdoc" / "data"
# 收集所有数据文件
datas = []
if DATA_DIR.exists():
for file_path in DATA_DIR.glob("*.json"):
datas.append((str(file_path), "ripperdoc/data"))
# 隐藏导入 - PyInstaller 有时无法自动检测这些
hiddenimports = [
# 核心依赖
"anthropic",
"openai",
"click",
"rich",
"textual",
"pydantic",
"aiofiles",
"prompt_toolkit",
"yaml",
"mcp",
"json_repair",
"tiktoken",
"charset_normalizer",
# Ripperdoc 内部模块
"ripperdoc.cli",
"ripperdoc.core",
"ripperdoc.tools",
"ripperdoc.utils",
"ripperdoc.data",
# LSP 相关
]
# 仅在环境已安装时才加入,避免在CI里出现假阳性 "Hidden import not found" 警告。
_optional_hiddenimports = [
"google.genai",
"tiktoken_ext",
"tiktoken_ext.openai_public",
"pygls.lsp",
"pygls.protocol",
]
def _module_available(module_name: str) -> bool:
try:
return find_spec(module_name) is not None
except ModuleNotFoundError:
return False
except Exception:
return False
for _module in _optional_hiddenimports:
if _module_available(_module):
hiddenimports.append(_module)
# 强制收集 rich 的 unicode 数据子模块,避免打包后动态导入缺失。
hiddenimports.extend(
[module for module in collect_submodules("rich._unicode_data") if module not in hiddenimports]
)
# Windows ARM 下 strip 会频繁触发文件格式警告(不影响产物),这里统一关闭。
WINDOWS_NO_STRIP = sys.platform == "win32"
STRIP_BINARIES = not WINDOWS_NO_STRIP
block_cipher = None
a = Analysis(
["ripperdoc/cli/cli.py"],
pathex=[str(ROOT_DIR)],
binaries=[],
datas=datas,
hiddenimports=hiddenimports,
hookspath=[str(ROOT_DIR / "scripts" / "pyinstaller_hooks")],
hooksconfig={},
runtime_hooks=[],
excludes=[
# 排除测试相关
"pytest",
"_pytest",
"tests",
# 排除开发工具
"black",
"ruff",
"mypy",
"pylint",
"flake8",
# 排除不需要的标准库
"tkinter",
"turtledemo",
"unittest",
"pydoc",
"doctest",
"lib2to3",
"xmlrpc",
"msilib",
"optparse",
"poplib",
"imaplib",
"nntplib",
"smtplib",
"smtpd",
"telnetlib",
"ftplib",
"webbrowser",
"cgi",
"cgitb",
"wsgiref",
# 排除不需要的第三方库
"IPython",
"ipywidgets",
"jupyter",
"jupyter_client",
"jupyter_core",
"nbconvert",
"nbformat",
"notebook",
"matplotlib",
"numpy",
"pandas",
"scipy",
"torch",
"tensorflow",
"keras",
"sklearn",
"scikit-learn",
"PIL",
"pillow",
"cv2",
"opencv",
"sympy",
"nose",
"sphinx",
"docutils",
],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
# 根据构建模式选择不同的打包方式
if BUILD_MODE == "onedir":
# 目录模式: 可执行文件 + 依赖文件 + 数据文件在同一目录
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name="ripperdoc",
debug=False,
bootloader_ignore_signals=False,
strip=STRIP_BINARIES,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name="ripperdoc",
)
else:
# 单文件模式: 所有内容打包成一个可执行文件
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name="ripperdoc",
debug=False,
bootloader_ignore_signals=False,
strip=STRIP_BINARIES,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=None,
)