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
307 lines (278 loc) · 10.8 KB
/
cgc.spec
File metadata and controls
307 lines (278 loc) · 10.8 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
# 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
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',
'asyncio',
'pkg_resources',
'threading',
'subprocess',
'socket',
'atexit',
]
# 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}")
# 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')
# 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=[],
hooksconfig={},
runtime_hooks=[],
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,
)