forked from andrewbartels1/SolidworksMCP-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-commands.ps1
More file actions
323 lines (281 loc) · 12.8 KB
/
Copy pathdev-commands.ps1
File metadata and controls
323 lines (281 loc) · 12.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# SolidWorks MCP Python - Development Commands for PowerShell (Windows 11)
# Run individual commands: .\dev-commands.ps1 dev-test
# Or source and call directly: . .\dev-commands.ps1; dev-test
param(
[string]$Command = ""
)
Write-Host "SolidWorks MCP Development Commands" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# ---------------------------------------------------------------------------
# Internal helpers
# ---------------------------------------------------------------------------
function Get-VenvPython {
return (Join-Path $PSScriptRoot ".venv\Scripts\python.exe")
}
function Ensure-Venv {
$venvDir = Join-Path $PSScriptRoot ".venv"
$venvCfg = Join-Path $venvDir "pyvenv.cfg"
$venvPy = Get-VenvPython
# Validate existing venv
if ((Test-Path $venvPy) -and (Test-Path $venvCfg)) {
& $venvPy -c "import sys, unicodedata; print(sys.version_info.major)" 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) {
& $venvPy -m pip --version 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) { return $true }
Write-Host "Bootstrapping pip in existing .venv..." -ForegroundColor Yellow
& $venvPy -m ensurepip --upgrade
& $venvPy -m pip --version 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) { return $true }
}
Write-Host ".venv is broken; recreating..." -ForegroundColor Yellow
Remove-Item -Recurse -Force $venvDir -ErrorAction SilentlyContinue
}
# Create with uv (preferred)
if (Get-Command uv -ErrorAction SilentlyContinue) {
Write-Host "Creating .venv with uv..." -ForegroundColor Cyan
uv venv .venv --python 3.11
if ($LASTEXITCODE -eq 0 -and (Test-Path $venvPy)) {
& $venvPy -m ensurepip --upgrade
return $true
}
}
# Fallback: py launcher or python
$pyCmd = if (Get-Command py -ErrorAction SilentlyContinue) { "py" } else { "python" }
$pyArgs = if ($pyCmd -eq "py") { @("-3.11") } else { @() }
Write-Host "Creating .venv with $pyCmd..." -ForegroundColor Cyan
& $pyCmd @pyArgs -m venv .venv
if ($LASTEXITCODE -eq 0 -and (Test-Path $venvPy)) {
& $venvPy -m ensurepip --upgrade
& $venvPy -m pip install --upgrade pip setuptools wheel | Out-Null
return $true
}
Write-Host "ERROR: Failed to create .venv. Install uv: https://docs.astral.sh/uv/" -ForegroundColor Red
return $false
}
function Invoke-Venv {
param([Parameter(Mandatory = $true)][string[]]$Args)
$venvPy = Get-VenvPython
if (-not (Test-Path $venvPy)) {
Write-Host "ERROR: .venv not found. Run: .\dev-commands.ps1 dev-install" -ForegroundColor Red
$global:LASTEXITCODE = 1
return
}
& $venvPy @Args
}
function Invoke-Pytest {
param([Parameter(Mandatory = $true)][string[]]$Args)
Invoke-Venv -Args (@("-m", "pytest") + $Args)
}
function Invoke-IntegrationCleanup {
Invoke-Venv @("tests/scripts/cleanup_generated_integration_artifacts.py")
if ($LASTEXITCODE -ne 0) {
Write-Host "Generated-artifact cleanup failed (non-blocking)." -ForegroundColor Yellow
}
}
# ---------------------------------------------------------------------------
# Commands
# ---------------------------------------------------------------------------
function dev-help {
Write-Host "Available Commands:" -ForegroundColor Green
Write-Host ""
Write-Host " dev-install Install/sync dependencies via uv (creates/repairs .venv)"
Write-Host " dev-install-ui Install/repair UI extras in .venv only"
Write-Host " dev-test Run test suite with coverage (excludes solidworks_only)"
Write-Host " dev-test-full Run full suite including real SolidWorks integration tests"
Write-Host " dev-lint Format + lint code (ruff format + ruff check)"
Write-Host " dev-format Format code only (ruff format)"
Write-Host " dev-build Build package for distribution"
Write-Host " dev-run Start the MCP server"
Write-Host " dev-ui Start FastAPI backend + Prefab dashboard"
Write-Host " dev-ui-probe Start FastAPI backend + Prefab probe target"
Write-Host " dev-docs-build Build documentation once (mkdocs build --clean)"
Write-Host " dev-docs-strict Build documentation in strict mode"
Write-Host " dev-docs-audit Run verbose + strict docs audit and write summary"
Write-Host " dev-docs Build and serve documentation (http://localhost:8000)"
Write-Host " dev-docs-discovery Index SolidWorks COM/VBA documentation (Windows + SW running)"
Write-Host " dev-clean Remove build/cache artifacts"
Write-Host ""
}
function dev-install {
Write-Host "Installing SolidWorks MCP Server..." -ForegroundColor Cyan
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Host "ERROR: uv is required. Install from: https://docs.astral.sh/uv/" -ForegroundColor Red
return
}
$ready = Ensure-Venv
if (-not $ready) { return }
$venvPy = Get-VenvPython
uv pip install --python $venvPy -e ".[dev,test,docs,ui,rag]"
if ($LASTEXITCODE -eq 0) {
Write-Host "Installation complete!" -ForegroundColor Green
} else {
Write-Host "Installation failed." -ForegroundColor Red
}
}
function dev-install-ui {
Write-Host "Installing/repairing UI extras in .venv..." -ForegroundColor Cyan
$ready = Ensure-Venv
if (-not $ready) { return }
$venvPy = Get-VenvPython
& $venvPy -m pip install "prefab-ui>=0.19.0" "fastapi>=0.115.0" "uvicorn>=0.24.0" -q
if ($LASTEXITCODE -eq 0) {
Write-Host "UI extras installed." -ForegroundColor Green
} else {
Write-Host "Failed to install UI extras." -ForegroundColor Red
}
}
function dev-test {
Write-Host "Running tests with coverage..." -ForegroundColor Cyan
$env:PY_KEY_VALUE_DISABLE_BEARTYPE = "true"
# Keep generated integration artifacts from previous runs from accumulating.
Invoke-IntegrationCleanup
Invoke-Pytest @(
"tests/",
"-m", "not solidworks_only and not smoke",
"-n", "auto",
"--cov=src/solidworks_mcp",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--durations=10",
"-v"
)
Invoke-IntegrationCleanup
if ($LASTEXITCODE -eq 0) {
Write-Host "Tests passed! Coverage: htmlcov/index.html" -ForegroundColor Green
} else {
Write-Host "Tests failed." -ForegroundColor Red
}
}
function dev-test-full {
Write-Host "Running full test suite (including real SolidWorks integration)..." -ForegroundColor Cyan
$env:PY_KEY_VALUE_DISABLE_BEARTYPE = "true"
$env:SOLIDWORKS_MCP_RUN_REAL_INTEGRATION = "true"
Invoke-Pytest @(
"tests/",
"-n", "1",
"--cov=src/solidworks_mcp",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--durations=10",
"-v"
)
if ($LASTEXITCODE -eq 0) {
Write-Host "Full tests passed!" -ForegroundColor Green
} else {
Write-Host "Full tests failed." -ForegroundColor Red
}
}
function dev-lint {
Write-Host "Formatting and linting..." -ForegroundColor Cyan
Invoke-Venv @("-m", "ruff", "format", "src/", "tests/")
if ($LASTEXITCODE -ne 0) { Write-Host "Formatting failed." -ForegroundColor Red; return }
Invoke-Venv @("-m", "ruff", "check", "src/", "tests/")
if ($LASTEXITCODE -eq 0) { Write-Host "Format + lint passed!" -ForegroundColor Green }
else { Write-Host "Lint issues found." -ForegroundColor Yellow }
}
function dev-format {
Write-Host "Formatting code..." -ForegroundColor Cyan
Invoke-Venv @("-m", "ruff", "format", "src/", "tests/")
if ($LASTEXITCODE -eq 0) { Write-Host "Format complete." -ForegroundColor Green }
else { Write-Host "Formatting failed." -ForegroundColor Red }
}
function dev-build {
Write-Host "Building package..." -ForegroundColor Cyan
Invoke-Venv @("-m", "build")
if ($LASTEXITCODE -eq 0) { Write-Host "Build complete! dist/" -ForegroundColor Green }
else { Write-Host "Build failed." -ForegroundColor Red }
}
function dev-run {
Write-Host "Starting MCP server..." -ForegroundColor Cyan
Invoke-Venv @("-m", "solidworks_mcp.server")
}
function dev-ui {
Write-Host "Starting UI (FastAPI + Prefab dashboard)..." -ForegroundColor Cyan
& (Join-Path $PSScriptRoot "run-ui.ps1") -FrontendTarget "src/solidworks_mcp/ui/prefab_dashboard.py"
}
function dev-ui-probe {
Write-Host "Starting UI probe alias (FastAPI + Prefab dashboard)..." -ForegroundColor Cyan
& (Join-Path $PSScriptRoot "run-ui.ps1") -FrontendTarget "src/solidworks_mcp/ui/prefab_dashboard.py"
}
function dev-docs {
Write-Host "Building docs..." -ForegroundColor Cyan
Invoke-Venv @("-m", "mkdocs", "build", "--clean")
if ($LASTEXITCODE -ne 0) { Write-Host "Docs build failed." -ForegroundColor Red; return }
Write-Host "Serving at http://localhost:8000 (Ctrl+C to stop)..." -ForegroundColor Yellow
Invoke-Venv @("-m", "mkdocs", "serve", "--dev-addr=localhost:8000")
}
function dev-docs-build {
Write-Host "Building docs..." -ForegroundColor Cyan
& (Join-Path $PSScriptRoot "scripts\docs\build-docs.ps1")
if ($LASTEXITCODE -eq 0) { Write-Host "Docs build passed." -ForegroundColor Green }
else { Write-Host "Docs build failed." -ForegroundColor Red }
}
function dev-docs-strict {
Write-Host "Building docs in strict mode..." -ForegroundColor Cyan
& (Join-Path $PSScriptRoot "scripts\docs\build-docs.ps1") -Strict
if ($LASTEXITCODE -eq 0) { Write-Host "Strict docs build passed." -ForegroundColor Green }
else { Write-Host "Strict docs build reported warnings/errors." -ForegroundColor Yellow }
}
function dev-docs-audit {
Write-Host "Running docs audit (verbose + strict)..." -ForegroundColor Cyan
& (Join-Path $PSScriptRoot "scripts\docs\audit-docs.ps1")
if ($LASTEXITCODE -eq 0) { Write-Host "Docs audit completed." -ForegroundColor Green }
else { Write-Host "Docs audit failed." -ForegroundColor Red }
}
function dev-docs-discovery {
Write-Host "Indexing SolidWorks COM and VBA documentation..." -ForegroundColor Cyan
# $IsWindows and PSVersionTable.Platform only exist in PS 6+; PS 5.1 is Windows-exclusive so treat missing Platform as Windows
$isWindowsOS = $IsWindows -or ($PSVersionTable.Platform -eq "Win32NT") -or ($null -eq $PSVersionTable.Platform)
if (-not $isWindowsOS) {
Write-Host "ERROR: Windows only." -ForegroundColor Red
return
}
$swProcess = Get-Process | Where-Object { $_.ProcessName -like "*sldworks*" }
if (-not $swProcess) {
Write-Host "WARNING: SolidWorks not running. Start it and retry." -ForegroundColor Yellow
return
}
$env:PY_KEY_VALUE_DISABLE_BEARTYPE = "true"
$repoRoot = $PSScriptRoot.Replace("'", "''")
$pythonCode = @"
import sys
from pathlib import Path
sys.path.insert(0, str(Path(r'$repoRoot') / 'src'))
from solidworks_mcp.tools.docs_discovery import SolidWorksDocsDiscovery
d = SolidWorksDocsDiscovery()
d.discover_all()
f = d.save_index()
s = d.create_search_summary()
print('COM Objects:', s.get('total_com_objects'), ' Methods:', s.get('total_methods'), ' Index:', f)
"@
Invoke-Venv -Args @("-c", $pythonCode)
if ($LASTEXITCODE -eq 0) { Write-Host "Discovery complete." -ForegroundColor Green }
else { Write-Host "Discovery failed." -ForegroundColor Red }
}
function dev-clean {
Write-Host "Cleaning build artifacts..." -ForegroundColor Cyan
@("build", "dist", "htmlcov", ".pytest_cache", ".mypy_cache", "site", "*.egg-info") | ForEach-Object {
Get-ChildItem -Path . -Filter $_ -Recurse -Directory -ErrorAction SilentlyContinue |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
}
Remove-Item -Path .coverage, coverage.xml -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path . -Filter "*.egg-info" -Recurse | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path . -Filter "__pycache__" -Recurse | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path . -Filter "*.pyc" -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Host "Clean complete!" -ForegroundColor Green
}
# ---------------------------------------------------------------------------
# Dispatch
# ---------------------------------------------------------------------------
if ([string]::IsNullOrWhiteSpace($Command) -or $Command -eq "dev-help") {
dev-help
} elseif (Get-Command -Name $Command -CommandType Function -ErrorAction SilentlyContinue) {
& $Command
} else {
Write-Host "Unknown command: $Command" -ForegroundColor Red
dev-help
exit 1
}