forked from CodeGraphContext/CodeGraphContext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgc.spec
More file actions
382 lines (349 loc) · 14.7 KB
/
cgc.spec
File metadata and controls
382 lines (349 loc) · 14.7 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# cgc.spec
# Multi-platform PyInstaller build spec for CodeGraphContext
# Supports: Linux (x86_64/Aarch64), Windows, macOS
import sys
import os
from pathlib import Path
from PyInstaller.utils.hooks import collect_data_files, collect_submodules, collect_all, collect_entry_point
block_cipher = None
# ── Environment Detection ──────────────────────────────────────────────────
is_win = sys.platform == 'win32'
is_mac = sys.platform == 'darwin'
is_linux = sys.platform == 'linux' or sys.platform == 'linux2'
# Find site-packages dynamically using the 'site' module
import site
prefix = Path(sys.prefix)
search_paths = [prefix]
# Add standard site-packages locations
try:
search_paths.extend([Path(p) for p in site.getsitepackages()])
except AttributeError:
# Getsitepackages not available in some venv configs
pass
# Add user-local site-packages
search_paths.append(Path(site.getusersitepackages()))
# Ensure we only have unique, existing paths
search_paths = list(set([p for p in search_paths if p.exists()]))
print(f"Detected Platform: {sys.platform}")
print(f"Searching for dependencies in: {[str(p) for p in search_paths]}")
# ── 1. Component Lists (Binaries, Datas, Hidden Imports) ───────────────────
binaries = []
datas = []
hidden_imports = [
'codegraphcontext',
'codegraphcontext.cli',
'codegraphcontext.cli.main',
'codegraphcontext.cli.cli_helpers',
'codegraphcontext.cli.config_manager',
'codegraphcontext.cli.registry_commands',
'codegraphcontext.cli.setup_wizard',
'codegraphcontext.cli.setup_macos',
'codegraphcontext.cli.visualizer',
'codegraphcontext.core',
'codegraphcontext.core.database',
'codegraphcontext.core.database_falkordb',
'codegraphcontext.core.database_falkordb_remote',
'codegraphcontext.core.database_kuzu',
'codegraphcontext.core.falkor_worker',
'codegraphcontext.core.jobs',
'codegraphcontext.core.watcher',
'codegraphcontext.core.cgc_bundle',
'codegraphcontext.core.bundle_registry',
'codegraphcontext.server',
'codegraphcontext.tool_definitions',
'codegraphcontext.prompts',
'codegraphcontext.tools',
'codegraphcontext.tools.code_finder',
'codegraphcontext.tools.graph_builder',
'codegraphcontext.tools.package_resolver',
'codegraphcontext.tools.system',
'codegraphcontext.tools.scip_indexer',
'codegraphcontext.tools.scip_pb2',
'codegraphcontext.tools.advanced_language_query_tool',
'codegraphcontext.tools.languages',
'codegraphcontext.tools.languages.python',
'codegraphcontext.tools.languages.javascript',
'codegraphcontext.tools.languages.typescript',
'codegraphcontext.tools.languages.typescriptjsx',
'codegraphcontext.tools.languages.java',
'codegraphcontext.tools.languages.go',
'codegraphcontext.tools.languages.rust',
'codegraphcontext.tools.languages.c',
'codegraphcontext.tools.languages.cpp',
'codegraphcontext.tools.languages.ruby',
'codegraphcontext.tools.languages.php',
'codegraphcontext.tools.languages.csharp',
'codegraphcontext.tools.languages.kotlin',
'codegraphcontext.tools.languages.scala',
'codegraphcontext.tools.languages.swift',
'codegraphcontext.tools.languages.haskell',
'codegraphcontext.tools.languages.dart',
'codegraphcontext.tools.languages.perl',
'codegraphcontext.tools.query_tool_languages.python_toolkit',
'codegraphcontext.tools.query_tool_languages.javascript_toolkit',
'codegraphcontext.tools.query_tool_languages.typescript_toolkit',
'codegraphcontext.tools.query_tool_languages.java_toolkit',
'codegraphcontext.tools.query_tool_languages.go_toolkit',
'codegraphcontext.tools.query_tool_languages.rust_toolkit',
'codegraphcontext.tools.query_tool_languages.c_toolkit',
'codegraphcontext.tools.query_tool_languages.cpp_toolkit',
'codegraphcontext.tools.query_tool_languages.ruby_toolkit',
'codegraphcontext.tools.query_tool_languages.csharp_toolkit',
'codegraphcontext.tools.query_tool_languages.scala_toolkit',
'codegraphcontext.tools.query_tool_languages.swift_toolkit',
'codegraphcontext.tools.query_tool_languages.haskell_toolkit',
'codegraphcontext.tools.query_tool_languages.dart_toolkit',
'codegraphcontext.tools.query_tool_languages.perl_toolkit',
'codegraphcontext.tools.handlers.analysis_handlers',
'codegraphcontext.tools.handlers.indexing_handlers',
'codegraphcontext.tools.handlers.management_handlers',
'codegraphcontext.tools.handlers.query_handlers',
'codegraphcontext.tools.handlers.watcher_handlers',
'codegraphcontext.utils.debug_log',
'codegraphcontext.utils.tree_sitter_manager',
'codegraphcontext.utils.visualize_graph',
'kuzu',
'falkordb',
'redislite',
'neo4j',
'neo4j.io',
'neo4j.auth_management',
'neo4j.addressing',
'neo4j.routing',
'dotenv',
'typer',
'typer.core',
'typer.main',
'rich',
'rich.console',
'rich.table',
'rich.progress',
'rich.markup',
'rich.panel',
'tree_sitter',
'tree_sitter_language_pack',
'watchdog',
'watchdog.observers',
'watchdog.events',
'anyio',
'click',
'shellingham',
'httpx',
'httpcore',
'importlib',
'importlib.metadata',
'importlib.metadata._meta',
'importlib.metadata._adapters',
'importlib.metadata._itertools',
'importlib.metadata._functools',
'importlib.metadata._text',
'asyncio',
'pkg_resources',
'pkg_resources.extern',
'threading',
'subprocess',
'socket',
'atexit',
# plugin_registry.py discovers plugins via importlib.metadata.entry_points();
# each installed plugin's distribution metadata must be bundled so that
# entry_points(group=...) resolves correctly in a frozen executable.
'codegraphcontext.plugin_registry',
]
# ── Plugin entry-point metadata collection ────────────────────────────────
# PyInstaller cannot discover entry points at freeze time unless the
# distribution METADATA / entry_points.txt files are explicitly copied into
# the bundle. collect_entry_point() returns (datas, hidden_imports) for
# every distribution that declares the requested group.
_plugin_ep_groups = ['cgc_cli_plugins', 'cgc_mcp_plugins']
for _ep_group in _plugin_ep_groups:
try:
_ep_datas, _ep_hidden = collect_entry_point(_ep_group)
datas += _ep_datas
hidden_imports += _ep_hidden
except Exception as _ep_exc:
print(f"Warning: collect_entry_point('{_ep_group}') failed: {_ep_exc}")
# Bundle the codegraphcontext distribution metadata so that
# importlib.metadata.version("codegraphcontext") resolves in the frozen binary
# and PluginRegistry._get_cgc_version() returns the correct version string.
try:
datas += collect_data_files('codegraphcontext', includes=['**/*.dist-info/**/*'])
except Exception as _cgc_meta_exc:
print(f"Warning: collect_data_files('codegraphcontext') failed: {_cgc_meta_exc}")
# Bin extensions by platform
ext = '*.so'
if is_win:
ext = '*.pyd'
elif is_mac:
ext = '*.dylib'
def find_pkg_dir(name):
for p in sys.path:
if not p: continue
d = Path(p) / name
if d.exists():
return d
return None
def add_binary(package_path, pattern, target_subdir=None):
pkg_dir = find_pkg_dir(package_path)
if pkg_dir:
for f in pkg_dir.glob(pattern):
if f.is_file():
binaries.append((str(f), target_subdir or package_path))
else:
print(f"Warning: Could not find package directory: {package_path}")
# tree-sitter core
add_binary('tree_sitter', ext)
# tree-sitter-language-pack: ALL language bindings
add_binary('tree_sitter_language_pack/bindings', ext)
# other tree-sitter bindings
add_binary('tree_sitter_yaml', ext)
add_binary('tree_sitter_embedded_template', ext)
add_binary('tree_sitter_c_sharp', ext)
# KùzuDB complete collection
# We use find_pkg_dir to add the entire folder to datas, ensuring we don't miss any .so, .pyd, or .dylib files
kuzu_dir = find_pkg_dir('kuzu')
if kuzu_dir:
print(f"Force bundling entire Kuzu directory: {kuzu_dir}")
datas.append((str(kuzu_dir), 'kuzu'))
else:
print("WARNING: Could not find 'kuzu' directory to bundle!")
# ── 2. Bundle Logic (Aggressive FalkorDB Collection) ──────────────────────────
# Native dependencies detection
def find_all_native_binaries():
"""Scans all search paths for falkordb.so and redis-server to ensure they are tracked."""
found = []
for path in search_paths:
if path.exists():
# Find falkordb.so
for f in path.rglob('falkordb.so'):
if f.is_file():
print(f"Bundling found native module: {f}")
found.append((str(f), '.'))
# Find redislite's redis-server to ensure libcrypto/libssl dependencies are analyzed
for f in path.rglob('redis-server'):
if f.is_file() and 'redislite' in str(f):
print(f"Bundling redislite native server: {f}")
# Keep its original folder structure inside redislite/bin
found.append((str(f), 'redislite/bin'))
return found
# Add native binaries
binaries.extend(find_all_native_binaries())
# Tricky packages collection (redislite, falkordb, falkordblite)
if not is_win:
for pkg in ['redislite', 'falkordb', 'falkordblite']:
try:
t_datas, t_binaries, t_hiddenimports = collect_all(pkg)
datas += t_datas
binaries += t_binaries
hidden_imports += t_hiddenimports
except Exception as e:
print(f"Warning: collect_all failed for {pkg}: {e}")
# ── falkordblite: explicit auditwheel-vendored shared library collection ──────
# The Linux manylinux wheel ships shared libraries in a `falkordblite.libs/`
# directory (placed by auditwheel alongside the importable packages). This
# directory is NOT a Python package (no __init__.py), so collect_all/
# collect_dynamic_libs operating on top-level package names ('dummy',
# 'redislite') will not find it. We must explicitly scan for it and register
# every .so* in it as a binary so the dynamic linker can resolve libcrypto,
# libssl, and libgomp at runtime inside the frozen one-file executable.
#
# On macOS the equivalent vendored dylibs live in redislite/.dylibs/ and are
# already captured by collect_all('falkordblite') above. On Windows the
# package is not installed (sys_platform != 'win32' marker), so this block
# is also guarded.
if not is_win:
for _sp in search_paths:
_fdb_libs = _sp / 'falkordblite.libs'
if _fdb_libs.exists():
for _lib in _fdb_libs.iterdir():
if _lib.is_file() and not _lib.suffix == '.py':
print(f"Bundling falkordblite.libs: {_lib}")
binaries.append((str(_lib), 'falkordblite.libs'))
break # found; no need to check further paths
# falkordblite ships a top-level 'dummy' C extension (dummy.cpython-*.so).
# It is not an application import but must travel with the bundle as a
# sentinel that pip/auditwheel attaches native build metadata to.
# Collect it explicitly so PyInstaller does not silently drop it.
if not is_win:
# 'dummy' may resolve to the stdlib dummy module; guard by only picking up
# the .so file that lives directly in a site-packages root (where auditwheel
# places it) rather than in any sub-package directory.
for _sp in search_paths:
for _dummy_so in _sp.glob('dummy.cpython-*.so'):
if _dummy_so.is_file():
print(f"Bundling falkordblite dummy extension: {_dummy_so}")
binaries.append((str(_dummy_so), '.'))
break
# stdlibs: dynamically imports py3.py, py312.py, etc. via importlib
stdlibs_dir = find_pkg_dir('stdlibs')
if stdlibs_dir:
for f in stdlibs_dir.glob('*.py'):
datas.append((str(f), 'stdlibs'))
# mcp package data
datas += collect_data_files('mcp', includes=['**/*'])
# mcp.json shipped with CGC
mcp_json = Path('src/codegraphcontext/mcp.json')
if mcp_json.exists():
datas.append((str(mcp_json), 'codegraphcontext'))
# tree-sitter-language-pack: includes metadata needed at runtime
tslp_dir = find_pkg_dir('tree_sitter_language_pack')
if tslp_dir:
datas += collect_data_files('tree_sitter_language_pack', includes=['**/*'])
# ── 3. Final Adjustments ────────────────────────────────────────────────────
# Add redislite submodules to hidden imports
hidden_imports += collect_submodules('redislite')
hidden_imports += collect_submodules('falkordb')
# falkordblite's top_level.txt declares 'dummy' and 'redislite'.
# 'redislite' is covered above; add 'dummy' explicitly.
if not is_win:
hidden_imports.append('dummy')
# Add platform-specific watchers
if is_win:
hidden_imports.append('watchdog.observers.read_directory_changes')
elif is_linux:
hidden_imports.append('watchdog.observers.inotify')
hidden_imports.append('watchdog.observers.inotify_buffer')
elif is_mac:
hidden_imports.append('watchdog.observers.fsevents')
# ── 4. Analysis ──────────────────────────────────────────────────────────────
a = Analysis(
['cgc_entry.py'],
pathex=['src'],
binaries=binaries,
datas=datas,
hiddenimports=hidden_imports,
hookspath=['pyinstaller_hooks'],
hooksconfig={},
runtime_hooks=['pyinstaller_hooks/rthook_importlib_metadata.py'],
excludes=[
'tkinter', '_tkinter', 'matplotlib', 'numpy', 'pandas', 'scipy',
'PIL', 'cv2', 'torch', 'tensorflow', 'jupyter', 'notebook', 'IPython',
'pydoc', 'doctest', 'xmlrpc', 'lib2to3', 'test', 'unittest.mock',
],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
# ── 5. ONE-FILE EXE ──────────────────────────────────────────────────────────
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='cgc',
debug=False,
bootloader_ignore_signals=False,
strip=not is_win, # strip fails on windows often
upx=False,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=None,
)