-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathaish.spec
More file actions
255 lines (227 loc) · 6.66 KB
/
aish.spec
File metadata and controls
255 lines (227 loc) · 6.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# -*- mode: python ; coding: utf-8 -*-
"""
PyInstaller spec file for AI Shell
Build command: pyinstaller aish.spec
"""
import os
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
def _filter_linux_toolchain_libs(binaries):
"""Filter bundled shared libraries on Linux.
Why:
- PyInstaller's bootloader prepends the extracted/bundle directory to
LD_LIBRARY_PATH.
- If we ship an older toolchain library (libstdc++.so.6 / libgcc_s.so.1),
child processes (e.g. apt) may accidentally load it and fail with
GLIBCXX_* symbol version errors.
Default policy:
- Exclude toolchain libs (always).
- Exclude common system libs by default to prefer target system libraries.
Build-time override:
- Set AISH_PYI_EXCLUDE_SYSTEM_SOS=0 to keep bundling common system libs.
"""
if os.name != "posix":
return binaries
# Default to excluding system libs ("1").
exclude_system_sos = os.environ.get("AISH_PYI_EXCLUDE_SYSTEM_SOS", "1") == "1"
# Always exclude toolchain libs to avoid polluting child processes.
exclude_prefixes = {
"libstdc++.so.6",
"libgcc_s.so.1",
}
# Optional: rely on target system for common system libs.
if exclude_system_sos:
exclude_prefixes.update(
{
"libncursesw.so.",
"libtinfo.so.",
"libsqlite3.so.",
"libuuid.so.",
"libz.so.",
"libbz2.so.",
"liblzma.so.",
}
)
filtered = []
for entry in binaries:
# Expected format: (dest_name, src_name, typecode)
try:
dest_name, src_name, typecode = entry
except ValueError:
filtered.append(entry)
continue
base = os.path.basename(dest_name)
if any(base.startswith(prefix) for prefix in exclude_prefixes):
continue
filtered.append((dest_name, src_name, typecode))
return filtered
# Collect tiktoken data files from the build-time cache.
tiktoken_cache_root = os.environ.get(
"AISH_BUILD_TIKTOKEN_CACHE_DIR",
os.path.join("build", "tiktoken_cache"),
)
if not os.path.isdir(tiktoken_cache_root):
raise SystemExit(
"Missing build-time tiktoken cache. Run packaging/prefetch_tiktoken_cache.py before PyInstaller."
)
tiktoken_datas = [(os.path.join(tiktoken_cache_root, "*"), "tiktoken_cache")]
# Collect litellm tokenizers (for offline token counting)
litellm_datas = collect_data_files('litellm', includes=['litellm_core_utils/tokenizers/*'])
# Collect root-level JSON price/context data files
litellm_json_datas = collect_data_files('litellm', includes=['*.json'])
shell_hiddenimports = collect_submodules('aish.shell')
block_cipher = None
# Collect default skills directory
skills_datas = []
if os.path.exists('debian/skills'):
for skill_name in os.listdir('debian/skills'):
skill_path = os.path.join('debian/skills', skill_name)
if os.path.isdir(skill_path):
skills_datas.append((skill_path, os.path.join('aish', 'skills', skill_name)))
a = Analysis(
['main.py'],
pathex=['src'],
binaries=[],
datas=[
('src/aish/prompts', 'aish/prompts'),
('src/aish/i18n', 'aish/i18n'),
('src/aish/scripts/themes', 'aish/scripts/themes'),
('src/aish/scripts/templates', 'aish/scripts/templates'),
('src/aish/terminal/pty/bash_rc_wrapper.sh', 'aish/terminal/pty'),
] + tiktoken_datas + litellm_datas + litellm_json_datas + skills_datas,
hiddenimports=[
'aish.prompts',
'aish.shell',
'aish.config',
'aish.llm',
'aish.command',
'dotenv',
'litellm',
'yaml',
'pydantic',
'prompt_toolkit',
'prompt_toolkit.history',
'prompt_toolkit.auto_suggest',
'prompt_toolkit.completion',
'prompt_toolkit.shortcuts',
'rich',
'rich.console',
'rich.panel',
'rich.markdown',
'typer',
'click',
'asyncio',
'concurrent.futures',
'threading',
'pty',
'select',
'signal',
'subprocess',
'tempfile',
'termios',
'tty',
'shlex',
'tiktoken',
'tiktoken_ext',
'tiktoken_ext.openai_public',
'tiktoken.load',
'tiktoken.core',
'regex',
] + shell_hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[
'tkinter',
'matplotlib',
'numpy',
'scipy',
'pandas',
'wx',
'PyQt5',
'PyQt6',
'PySide2',
'PySide6',
],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
# Prevent bundling toolchain libs that may pollute child processes.
a.binaries = _filter_linux_toolchain_libs(a.binaries)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='aish',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
# Build the privileged sandbox daemon as a separate binary.
# This lets standalone deb packaging ship /usr/bin/aish-sandbox without relying
# on system Python or vendored site-packages.
a_sandbox = Analysis(
['src/aish/sandboxd.py'],
pathex=['src'],
binaries=[],
datas=[],
hiddenimports=[
'aish.security.sandbox_daemon',
'aish.security.sandbox_worker',
],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[
'tkinter',
'matplotlib',
'numpy',
'scipy',
'pandas',
'wx',
'PyQt5',
'PyQt6',
'PySide2',
'PySide6',
],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
# Same filtering for the sandbox daemon binary.
a_sandbox.binaries = _filter_linux_toolchain_libs(a_sandbox.binaries)
pyz_sandbox = PYZ(a_sandbox.pure, a_sandbox.zipped_data, cipher=block_cipher)
exe_sandbox = EXE(
pyz_sandbox,
a_sandbox.scripts,
a_sandbox.binaries,
a_sandbox.zipfiles,
a_sandbox.datas,
[],
name='aish-sandbox',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)