forked from BeehiveInnovations/pal-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_quality_checks.ps1
More file actions
260 lines (220 loc) · 8.21 KB
/
code_quality_checks.ps1
File metadata and controls
260 lines (220 loc) · 8.21 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
<#
.SYNOPSIS
Code quality checks script for PAL MCP server on Windows.
.DESCRIPTION
This PowerShell script performs code quality checks for the PAL MCP server project:
- Runs static analysis and linting tools on the codebase
- Ensures code style compliance and detects potential issues
- Can be integrated into CI/CD pipelines or used locally before commits
.PARAMETER Help
Displays help information for using the script.
.PARAMETER Verbose
Enables detailed output during code quality checks.
.EXAMPLE
.\code_quality_checks.ps1
Runs all code quality checks on the project.
.\code_quality_checks.ps1 -Verbose
Runs code quality checks with detailed output.
.NOTES
Project Author : BeehiveInnovations
Script Author : GiGiDKR (https://github.com/GiGiDKR)
Date : 07-05-2025
Version : See project documentation
References : https://github.com/BeehiveInnovations/pal-mcp-server
#>
#Requires -Version 5.1
[CmdletBinding()]
param(
[switch]$SkipTests,
[switch]$SkipLinting,
[switch]$VerboseOutput
)
# Set error action preference
$ErrorActionPreference = "Stop"
# Colors for output
function Write-ColorText {
param(
[Parameter(Mandatory)]
[string]$Text,
[string]$Color = "White"
)
Write-Host $Text -ForegroundColor $Color
}
function Write-Emoji {
param(
[Parameter(Mandatory)]
[string]$Emoji,
[Parameter(Mandatory)]
[string]$Text,
[string]$Color = "White"
)
Write-Host "$Emoji " -NoNewline
Write-ColorText $Text -Color $Color
}
Write-Emoji "🔍" "Running Code Quality Checks for PAL MCP Server" -Color Cyan
Write-ColorText "=================================================" -Color Cyan
# Determine Python command
$pythonCmd = $null
$pipCmd = $null
if (Test-Path ".pal_venv") {
if ($IsWindows -or $env:OS -eq "Windows_NT") {
if (Test-Path ".pal_venv\Scripts\python.exe") {
$pythonCmd = ".pal_venv\Scripts\python.exe"
$pipCmd = ".pal_venv\Scripts\pip.exe"
}
} else {
if (Test-Path ".pal_venv/bin/python") {
$pythonCmd = ".pal_venv/bin/python"
$pipCmd = ".pal_venv/bin/pip"
}
}
if ($pythonCmd) {
Write-Emoji "✅" "Using venv" -Color Green
}
} elseif ($env:VIRTUAL_ENV) {
$pythonCmd = "python"
$pipCmd = "pip"
Write-Emoji "✅" "Using activated virtual environment: $env:VIRTUAL_ENV" -Color Green
} else {
Write-Emoji "❌" "No virtual environment found!" -Color Red
Write-ColorText "Please run: .\run-server.ps1 first to set up the environment" -Color Yellow
exit 1
}
Write-Host ""
# Check and install dev dependencies if needed
Write-Emoji "🔍" "Checking development dependencies..." -Color Cyan
$devDepsNeeded = $false
# List of dev tools to check
$devTools = @("ruff", "black", "isort", "pytest")
foreach ($tool in $devTools) {
$toolFound = $false
# Check in venv
if ($IsWindows -or $env:OS -eq "Windows_NT") {
if (Test-Path ".pal_venv\Scripts\$tool.exe") {
$toolFound = $true
}
} else {
if (Test-Path ".pal_venv/bin/$tool") {
$toolFound = $true
}
}
# Check in PATH
if (!$toolFound) {
try {
$null = Get-Command $tool -ErrorAction Stop
$toolFound = $true
} catch {
# Tool not found
}
}
if (!$toolFound) {
$devDepsNeeded = $true
break
}
}
if ($devDepsNeeded) {
Write-Emoji "📦" "Installing development dependencies..." -Color Yellow
try {
& $pipCmd install -q -r requirements-dev.txt
if ($LASTEXITCODE -ne 0) {
throw "Failed to install dev dependencies"
}
Write-Emoji "✅" "Development dependencies installed" -Color Green
} catch {
Write-Emoji "❌" "Failed to install development dependencies" -Color Red
Write-ColorText "Error: $_" -Color Red
exit 1
}
} else {
Write-Emoji "✅" "Development dependencies already installed" -Color Green
}
# Set tool paths
if ($IsWindows -or $env:OS -eq "Windows_NT") {
$ruffCmd = if (Test-Path ".pal_venv\Scripts\ruff.exe") { ".pal_venv\Scripts\ruff.exe" } else { "ruff" }
$blackCmd = if (Test-Path ".pal_venv\Scripts\black.exe") { ".pal_venv\Scripts\black.exe" } else { "black" }
$isortCmd = if (Test-Path ".pal_venv\Scripts\isort.exe") { ".pal_venv\Scripts\isort.exe" } else { "isort" }
$pytestCmd = if (Test-Path ".pal_venv\Scripts\pytest.exe") { ".pal_venv\Scripts\pytest.exe" } else { "pytest" }
} else {
$ruffCmd = if (Test-Path ".pal_venv/bin/ruff") { ".pal_venv/bin/ruff" } else { "ruff" }
$blackCmd = if (Test-Path ".pal_venv/bin/black") { ".pal_venv/bin/black" } else { "black" }
$isortCmd = if (Test-Path ".pal_venv/bin/isort") { ".pal_venv/bin/isort" } else { "isort" }
$pytestCmd = if (Test-Path ".pal_venv/bin/pytest") { ".pal_venv/bin/pytest" } else { "pytest" }
}
Write-Host ""
# Step 1: Linting and Formatting
if (!$SkipLinting) {
Write-Emoji "📋" "Step 1: Running Linting and Formatting Checks" -Color Cyan
Write-ColorText "--------------------------------------------------" -Color Cyan
try {
Write-Emoji "🔧" "Running ruff linting with auto-fix..." -Color Yellow
& $ruffCmd check --fix --exclude test_simulation_files --exclude .pal_venv
if ($LASTEXITCODE -ne 0) {
throw "Ruff linting failed"
}
Write-Emoji "🎨" "Running black code formatting..." -Color Yellow
& $blackCmd . --exclude="test_simulation_files/" --exclude=".pal_venv/"
if ($LASTEXITCODE -ne 0) {
throw "Black formatting failed"
}
Write-Emoji "📦" "Running import sorting with isort..." -Color Yellow
& $isortCmd . --skip-glob=".pal_venv/*" --skip-glob="test_simulation_files/*"
if ($LASTEXITCODE -ne 0) {
throw "Import sorting failed"
}
Write-Emoji "✅" "Verifying all linting passes..." -Color Yellow
& $ruffCmd check --exclude test_simulation_files --exclude .pal_venv
if ($LASTEXITCODE -ne 0) {
throw "Final linting verification failed"
}
Write-Emoji "✅" "Step 1 Complete: All linting and formatting checks passed!" -Color Green
} catch {
Write-Emoji "❌" "Step 1 Failed: Linting and formatting checks failed" -Color Red
Write-ColorText "Error: $_" -Color Red
exit 1
}
} else {
Write-Emoji "⏭️" "Skipping linting and formatting checks" -Color Yellow
}
Write-Host ""
# Step 2: Unit Tests
if (!$SkipTests) {
Write-Emoji "🧪" "Step 2: Running Complete Unit Test Suite" -Color Cyan
Write-ColorText "---------------------------------------------" -Color Cyan
try {
Write-Emoji "🏃" "Running unit tests (excluding integration tests)..." -Color Yellow
$pytestArgs = @("tests/", "-v", "-x", "-m", "not integration")
if ($VerboseOutput) {
$pytestArgs += "--verbose"
}
& $pythonCmd -m pytest @pytestArgs
if ($LASTEXITCODE -ne 0) {
throw "Unit tests failed"
}
Write-Emoji "✅" "Step 2 Complete: All unit tests passed!" -Color Green
} catch {
Write-Emoji "❌" "Step 2 Failed: Unit tests failed" -Color Red
Write-ColorText "Error: $_" -Color Red
exit 1
}
} else {
Write-Emoji "⏭️" "Skipping unit tests" -Color Yellow
}
Write-Host ""
# Step 3: Final Summary
Write-Emoji "🎉" "All Code Quality Checks Passed!" -Color Green
Write-ColorText "==================================" -Color Green
if (!$SkipLinting) {
Write-Emoji "✅" "Linting (ruff): PASSED" -Color Green
Write-Emoji "✅" "Formatting (black): PASSED" -Color Green
Write-Emoji "✅" "Import sorting (isort): PASSED" -Color Green
} else {
Write-Emoji "⏭️" "Linting: SKIPPED" -Color Yellow
}
if (!$SkipTests) {
Write-Emoji "✅" "Unit tests: PASSED" -Color Green
} else {
Write-Emoji "⏭️" "Unit tests: SKIPPED" -Color Yellow
}
Write-Host ""
Write-Emoji "🚀" "Your code is ready for commit and GitHub Actions!" -Color Green
Write-Emoji "💡" "Remember to add simulator tests if you modified tools" -Color Yellow