-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdev-tools.ps1
More file actions
220 lines (191 loc) · 7.72 KB
/
Copy pathdev-tools.ps1
File metadata and controls
220 lines (191 loc) · 7.72 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
# PowerShell script for Edge Mining Development Tools (Windows alternative to Makefile)
param(
[Parameter(Position=0)]
[string]$Command = "help"
)
# Variables
$VENV = ".venv\Scripts"
$PYTHON = "$VENV\python.exe"
$PIP = "$VENV\pip.exe"
$PRE_COMMIT = "$VENV\pre-commit.exe"
function Show-Help {
Write-Host "Edge Mining App - Development and Docker Commands (PowerShell)" -ForegroundColor Green
Write-Host "============================================================" -ForegroundColor Green
Write-Host ""
Write-Host "Development:" -ForegroundColor Yellow
Write-Host " setup - Set up full development environment (core + frontend)"
Write-Host " venv - Create .venv and install all Python dependencies"
Write-Host " dev-core - Set up core backend development environment only"
Write-Host " dev-frontend - Install frontend dependencies only"
Write-Host " format - Format core code with ruff"
Write-Host " lint - Run all linting checks on core"
Write-Host " lint-fix - Run linting and auto-fix on core"
Write-Host " test - Run core tests"
Write-Host " test-cov - Run core tests with coverage"
Write-Host " pre-commit - Run pre-commit hooks on all files"
Write-Host " pre-commit-install - Install pre-commit hooks"
Write-Host " clean - Clean cache and temporary files"
Write-Host ""
Write-Host "Docker:" -ForegroundColor Yellow
Write-Host " build - Build the Docker image (frontend + backend + nginx)"
Write-Host " up - Start the application (docker compose up -d)"
Write-Host " down - Stop the application (docker compose down)"
Write-Host " restart - Rebuild and restart the application"
Write-Host " logs - Follow application logs"
Write-Host ""
Write-Host "Usage: .\dev-tools.ps1 [command]" -ForegroundColor Cyan
Write-Host "Example: .\dev-tools.ps1 setup" -ForegroundColor Cyan
}
function Setup-Venv {
Write-Host "🐍 Creating virtual environment and installing dependencies..." -ForegroundColor Blue
if (-not (Test-Path .venv)) {
& python3 -m venv .venv
}
& $PIP install --upgrade pip
& $PIP install -r core\requirements.txt
Write-Host "✅ Virtual environment ready!" -ForegroundColor Green
}
function Setup-DevCore {
Write-Host "🐍 Setting up core backend..." -ForegroundColor Blue
& $PIP install -r core\requirements-dev.txt
Write-Host "✅ Core backend setup complete!" -ForegroundColor Green
}
function Setup-DevFrontend {
Write-Host "🌐 Installing frontend dependencies..." -ForegroundColor Blue
Push-Location frontend
& npm install
Pop-Location
Write-Host "✅ Frontend dependencies installed!" -ForegroundColor Green
}
function Setup-Environment {
Setup-Venv
Setup-DevCore
Setup-DevFrontend
Install-PreCommitHooks
Write-Host "✅ Full development environment setup complete!" -ForegroundColor Green
}
function Format-Code {
Write-Host "🔧 Formatting code..." -ForegroundColor Blue
Push-Location core
& ..\.venv\Scripts\python.exe -m ruff format edge_mining/ tests/
Pop-Location
Write-Host "✅ Code formatting complete!" -ForegroundColor Green
}
function Run-Lint {
Write-Host "🔍 Running linting checks..." -ForegroundColor Blue
Push-Location core
& ..\.venv\Scripts\python.exe -m ruff check edge_mining/
& ..\.venv\Scripts\python.exe -m mypy edge_mining/
& ..\.venv\Scripts\python.exe -m bandit -r edge_mining/ --skip B311,B104
Pop-Location
Write-Host "✅ Linting complete!" -ForegroundColor Green
}
function Run-LintFix {
Write-Host "🔧 Running auto-fixable linting..." -ForegroundColor Blue
Push-Location core
& ..\.venv\Scripts\python.exe -m ruff check --fix edge_mining/
& ..\.venv\Scripts\python.exe -m ruff format edge_mining/
Pop-Location
Write-Host "✅ Auto-fix complete!" -ForegroundColor Green
}
function Run-Tests {
Write-Host "🧪 Running tests..." -ForegroundColor Blue
Push-Location core
& ..\.venv\Scripts\python.exe -m pytest tests/ -v
Pop-Location
Write-Host "✅ Tests complete!" -ForegroundColor Green
}
function Run-TestsWithCoverage {
Write-Host "🧪 Running tests with coverage..." -ForegroundColor Blue
Push-Location core
& ..\.venv\Scripts\python.exe -m pytest tests/ -v --cov=edge_mining --cov-report=html --cov-report=term
Pop-Location
Write-Host "✅ Tests with coverage complete!" -ForegroundColor Green
}
function Run-PreCommit {
Write-Host "🔧 Running pre-commit hooks..." -ForegroundColor Blue
& $PRE_COMMIT run --all-files
Write-Host "✅ Pre-commit complete!" -ForegroundColor Green
}
function Install-PreCommitHooks {
Write-Host "🔧 Installing pre-commit hooks..." -ForegroundColor Blue
& $PRE_COMMIT install
Write-Host "✅ Pre-commit hooks installed!" -ForegroundColor Green
}
function Clean-Cache {
Write-Host "🧹 Cleaning cache and temporary files..." -ForegroundColor Blue
Push-Location core
# Remove __pycache__ directories
Get-ChildItem -Path . -Recurse -Directory -Name "__pycache__" | ForEach-Object {
Remove-Item -Path $_ -Recurse -Force -ErrorAction SilentlyContinue
}
# Remove .pyc and .pyo files
Get-ChildItem -Path . -Recurse -Include "*.pyc", "*.pyo" | Remove-Item -Force -ErrorAction SilentlyContinue
# Remove .egg-info directories
Get-ChildItem -Path . -Recurse -Directory -Name "*.egg-info" | ForEach-Object {
Remove-Item -Path $_ -Recurse -Force -ErrorAction SilentlyContinue
}
# Remove build artifacts
@("build", "dist", ".coverage", "htmlcov", ".pytest_cache") | ForEach-Object {
if (Test-Path $_) {
Remove-Item -Path $_ -Recurse -Force -ErrorAction SilentlyContinue
}
}
Pop-Location
# Remove frontend temp files
if (Test-Path "frontend\node_modules\.tmp") {
Remove-Item -Path "frontend\node_modules\.tmp" -Recurse -Force -ErrorAction SilentlyContinue
}
Write-Host "✅ Cleanup complete!" -ForegroundColor Green
}
function Docker-Build {
Write-Host "🐳 Building Docker image..." -ForegroundColor Blue
& docker compose build
Write-Host "✅ Docker build complete!" -ForegroundColor Green
}
function Docker-Up {
Write-Host "🐳 Starting application..." -ForegroundColor Blue
& docker compose up -d
Write-Host "✅ Application started!" -ForegroundColor Green
}
function Docker-Down {
Write-Host "🐳 Stopping application..." -ForegroundColor Blue
& docker compose down
Write-Host "✅ Application stopped!" -ForegroundColor Green
}
function Docker-Restart {
Write-Host "🐳 Rebuilding and restarting application..." -ForegroundColor Blue
& docker compose build
& docker compose up -d
Write-Host "✅ Application restarted!" -ForegroundColor Green
}
function Docker-Logs {
& docker compose logs -f
}
# Main command dispatcher
switch ($Command.ToLower()) {
"help" { Show-Help }
"setup" { Setup-Environment }
"venv" { Setup-Venv }
"dev-core" { Setup-DevCore }
"dev-frontend" { Setup-DevFrontend }
"format" { Format-Code }
"lint" { Run-Lint }
"lint-fix" { Run-LintFix }
"test" { Run-Tests }
"test-cov" { Run-TestsWithCoverage }
"pre-commit" { Run-PreCommit }
"pre-commit-install" { Install-PreCommitHooks }
"clean" { Clean-Cache }
"build" { Docker-Build }
"up" { Docker-Up }
"down" { Docker-Down }
"restart" { Docker-Restart }
"logs" { Docker-Logs }
default {
Write-Host "Unknown command: $Command" -ForegroundColor Red
Write-Host ""
Show-Help
exit 1
}
}