forked from CodeBoarding/CodeBoarding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
375 lines (289 loc) Β· 12.5 KB
/
setup.py
File metadata and controls
375 lines (289 loc) Β· 12.5 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
import os
import platform
import shutil
import subprocess
import sys
from pathlib import Path
def check_uv_environment():
"""Validate that we're running within a uv virtual environment."""
print("Step: Environment validation started")
# Check if we're in a virtual environment
if not hasattr(sys, 'base_prefix') or sys.base_prefix == sys.prefix:
print("Step: Environment validation finished: failure - Not in virtual environment")
print("Please create and activate a uv environment first:")
print(" uv venv")
print(" source .venv/bin/activate # On Unix/Mac")
print(" .venv\\Scripts\\activate # On Windows")
sys.exit(1)
# Check if it's specifically a uv environment
venv_path = Path(sys.prefix)
uv_marker = venv_path / "pyvenv.cfg"
if uv_marker.exists():
with open(uv_marker, 'r') as f:
content = f.read()
if 'uv' not in content.lower():
print("Step: Environment validation finished: warning - May not be uv environment")
print("Step: Environment validation finished: success")
def install_requirements():
"""Install Python requirements using uv pip."""
print("Step: Requirements installation started")
requirements_file = 'requirements.txt'
if not os.path.exists(requirements_file):
print("Step: Requirements installation finished: failure - No requirements file found")
sys.exit(1)
try:
subprocess.run([
'uv', 'pip', 'install', '-r', requirements_file
], check=True, capture_output=True, text=True)
print("Step: Requirements installation finished: success")
except subprocess.CalledProcessError as e:
print(f"Step: Requirements installation finished: failure - {e}")
sys.exit(1)
def check_npm():
"""Check if npm is installed on the system."""
print("Step: npm check started")
npm_path = shutil.which('npm')
if npm_path:
try:
result = subprocess.run(['npm', '--version'], capture_output=True, text=True, check=True)
print(f"Step: npm check finished: success (version {result.stdout.strip()})")
return True
except:
print(
"Step: npm check finished: failure - npm command failed. Skipping TypeScript Language Server installation.")
return False
else:
print("Step: npm check finished: failure - npm not found")
print(" Install Node.js from: https://nodejs.org/")
return False
def install_typescript_language_server():
"""Install TypeScript Language Server using npm in the servers directory."""
print("Step: TypeScript Language Server installation started")
servers_dir = Path("static_analyzer/servers")
servers_dir.mkdir(parents=True, exist_ok=True)
original_cwd = os.getcwd()
try:
# Change to the servers directory
os.chdir(servers_dir)
# Initialize package.json if it doesn't exist
if not Path("package.json").exists():
subprocess.run(['npm', 'init', '-y'], check=True, capture_output=True, text=True)
# Install typescript-language-server and typescript
subprocess.run(['npm', 'install', 'typescript-language-server', 'typescript'], check=True, capture_output=True,
text=True)
# Verify the installation
ts_lsp_path = Path("./node_modules/.bin/typescript-language-server")
if ts_lsp_path.exists():
print("Step: TypeScript Language Server installation finished: success")
else:
print("Step: TypeScript Language Server installation finished: warning - Binary not found")
return True
except subprocess.CalledProcessError as e:
print(f"Step: TypeScript Language Server installation finished: failure - {e}")
return False
except Exception as e:
print(f"Step: TypeScript Language Server installation finished: failure - {e}")
return False
finally:
# Always return to original directory
os.chdir(original_cwd)
def download_file_from_gdrive(file_id, destination):
"""Download a file from Google Drive with proper handling of large files."""
import requests
# First try direct download
url = f"https://drive.google.com/uc?export=download&id={file_id}"
session = requests.Session()
response = session.get(url, stream=True)
# Check if we need to handle the download confirmation
token = None
for key, value in response.cookies.items():
if key.startswith('download_warning'):
token = value
break
if token:
# Handle large file download confirmation
params = {'id': file_id, 'confirm': token}
response = session.get(url, params=params, stream=True)
# Save the file
with open(destination, 'wb') as f:
for chunk in response.iter_content(chunk_size=32768):
if chunk:
f.write(chunk)
return response.status_code == 200
def download_binary_from_gdrive():
"""Download binaries from Google Drive."""
print("Step: Binary download started")
# File IDs extracted from your share links
mac_files = {
"py-lsp": "1a8FaSGq27dyrN5yrKKMOWqfm3H8BK9Zf",
"tokei": "1IKJSB7DHXAFZZQfwGOt6LypVUDlCQTLc",
"gopls": "1gROk7g88qNDg7eGWqtzOVqitktUXA65c"
}
win_files = {
"py-lsp": "1XKRsteNhUpu2eGhkYqRhXDvJYGhBpV01",
"tokei": "15dKUK0bSZ1dUexbJpnx5WSv_Lqj1kyWK",
"gopls": "162AdxaSb58IPNv_vvqTWUTtZJIo8Xrf_"
}
linux_files = {
"py-lsp": "17XcohKWZKHv26DgRIdrxcPRMN0LKyt0i",
"tokei": "1Wbx3bK0j-5c-hTJCfPcd86jqfQY0JsvF",
"gopls": "1MYlJiT2fOb9aIQnlB7jRCE6cxQ5_71U2",
}
system = platform.system()
if system == "Darwin":
file_ids = mac_files
elif system == "Windows":
file_ids = win_files
elif system == "Linux":
file_ids = linux_files
else:
print(f"Step: Binary download finished: failure - Unsupported OS: {system}")
return
# Create servers directory
servers_dir = Path("static_analyzer/servers")
servers_dir.mkdir(parents=True, exist_ok=True)
# Download each binary
success_count = 0
for binary_name, file_id in file_ids.items():
binary_path = servers_dir / binary_name
try:
# Remove existing file if it exists
if binary_path.exists():
binary_path.unlink()
# Download the file
success = download_file_from_gdrive(file_id, binary_path)
if success and binary_path.exists():
# Make the binary executable on Unix-like systems
if platform.system() != 'Windows':
os.chmod(binary_path, 0o755)
# Verify the file is not empty
if binary_path.stat().st_size > 0:
success_count += 1
else:
binary_path.unlink() # Remove empty file
except Exception as e:
pass # Continue with other downloads
if success_count == len(file_ids):
print("Step: Binary download finished: success")
elif success_count > 0:
print(f"Step: Binary download finished: partial success ({success_count}/{len(file_ids)} binaries)")
else:
print("Step: Binary download finished: failure - No binaries downloaded")
def update_static_analysis_config():
"""Update static_analysis_config.yml with correct paths to binaries."""
print("Step: Configuration update started")
import yaml
config_path = Path("static_analysis_config.yml")
if not config_path.exists():
print("Step: Configuration update finished: failure - static_analysis_config.yml not found")
return
# Read the current configuration
with open(config_path, 'r') as f:
config = yaml.safe_load(f)
# Get the absolute path to the project root
project_root = Path.cwd().resolve()
servers_dir = project_root / "static_analyzer" / "servers"
updates = 0
# Update Python LSP server path
py_lsp_path = servers_dir / "py-lsp"
if py_lsp_path.exists():
config['lsp_servers']['python']['command'][0] = str(py_lsp_path)
updates += 1
# Update TypeScript Language Server path
ts_lsp_path = servers_dir / "node_modules" / ".bin" / "typescript-language-server"
if ts_lsp_path.exists():
config['lsp_servers']['typescript']['command'][0] = str(ts_lsp_path)
updates += 1
# Update tokei tool path
tokei_path = servers_dir / "tokei"
if tokei_path.exists():
config['tools']['tokei']['command'][0] = str(tokei_path)
updates += 1
# Write the updated configuration back to file
with open(config_path, 'w') as f:
yaml.safe_dump(config, f, default_flow_style=False, sort_keys=False)
print(f"Step: Configuration update finished: success ({updates} paths updated)")
def init_dot_env_file():
"""Initialize .env file with default configuration and commented examples."""
print("Step: .env file creation started")
env_file_path = Path(".env")
# Get the absolute path to the project root
project_root = Path.cwd().resolve()
# Environment variables content
env_content = f"""# CodeBoarding Environment Configuration
# Generated by setup.py
# ============================================================================
# ACTIVE CONFIGURATION
# ============================================================================
# LLM Provider Configuration (uncomment and configure one)
OLLAMA_BASE_URL=http://localhost:11434
# Core Configuration
REPO_ROOT={project_root}/repos
STATIC_ANALYSIS_CONFIG={project_root}/static_analysis_config.yml
ROOT_RESULT={project_root}/results
PROJECT_ROOT={project_root}
DIAGRAM_DEPTH_LEVEL=1
CACHING_DOCUMENTATION=false
# ============================================================================
# LLM PROVIDER OPTIONS (uncomment and configure as needed)
# ============================================================================
# OpenAI Configuration
# OPENAI_API_KEY=your_openai_api_key_here
# OPENAI_BASE_URL=https://api.openai.com/v1 # Optional: Custom OpenAI endpoint
# Anthropic Configuration
# ANTHROPIC_API_KEY=your_anthropic_api_key_here
# Google AI Configuration
# GOOGLE_API_KEY=your_google_api_key_here
# AWS Bedrock Configuration
# AWS_BEARER_TOKEN_BEDROCK=your_aws_bearer_token_here
# ============================================================================
# OPTIONAL SERVICES
# ============================================================================
# GitHub Integration
# GITHUB_TOKEN=your_github_token_here # For accessing private repositories
# LangSmith Tracing (Optional)
# LANGSMITH_TRACING=false
# LANGSMITH_ENDPOINT=https://api.smith.langchain.com
# LANGSMITH_PROJECT=your_project_name
# LANGCHAIN_API_KEY=your_langchain_api_key_here
# ============================================================================
# NOTES
# ============================================================================
#
# Tip: Our experience has shown that using Google Gemini-2.5-Pro yields
# the best results for complex diagram generation tasks.
#
# Configuration: After setup, verify paths in static_analysis_config.yml
# point to the correct executables for your system.
#
# Documentation: Visit https://codeboarding.org for more information
#
"""
# Write the .env file
try:
with open(env_file_path, 'w') as f:
f.write(env_content)
print("Step: .env file creation finished: success")
except Exception as e:
print(f"Step: .env file creation finished: failure - {e}")
if __name__ == "__main__":
print("π CodeBoarding Installation Script")
print("=" * 40)
# Step 1: Validate uv environment
check_uv_environment()
# Step 2: Install Python requirements
install_requirements()
# Step 3: Check for npm and install TypeScript Language Server if available
npm_available = check_npm()
if npm_available:
install_typescript_language_server()
# Step 4: Download binary from Google Drive (fallback if npm installation failed)
download_binary_from_gdrive()
# Step 5: Update configuration file with absolute paths
update_static_analysis_config()
# Step 6: Initialize .env file
init_dot_env_file()
print("\n" + "=" * 40)
print("π Installation completed!")
print("π Don't forget to configure your .env file with your preferred LLM provider!")
print("All set you can run: python demo.py <github_repo_url> --output-dir <output_path>")