-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmake.ps1
More file actions
177 lines (154 loc) · 5.6 KB
/
Copy pathmake.ps1
File metadata and controls
177 lines (154 loc) · 5.6 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
<#
.SYNOPSIS
Admin script for setting up, activating, testing, linting, and cleaning your project venv with uv.
.PARAMETER task
What to do: 'active', 'make', 'update', 'test', 'lint', 'builddocs', 'servedocs', or 'clean'.
Defaults to 'active'.
#>
param (
[ValidateSet("active","make","update","test","lint","audit","builddocs","servedocs","clean")]
[string]$task = "active"
)
$ErrorActionPreference = 'Stop'
$UV_VERSION = "0.11.21"
$PIP_AUDIT_VERSION = "2.10.0"
# Ensure we run from repo root
Push-Location (Split-Path -Parent $MyInvocation.MyCommand.Definition)
# --- read exact Python version from .python-version ---
if (Test-Path ".\.python-version") {
$pythonVersion = (Get-Content ".\.python-version" -ErrorAction Stop).Trim()
if (-not $pythonVersion) {
Throw ".python-version is empty. Write '3.14' in it."
}
} else {
Throw "Required file .python-version not found. Create it with '3.14' as it's only content."
}
function Ensure-PythonPath {
if ($env:PYTHONPATH) {
if (-not ($env:PYTHONPATH -match [regex]::Escape($PWD))) {
$env:PYTHONPATH = "$PWD;$env:PYTHONPATH"
Write-Output "`nPYTHONPATH updated to: $env:PYTHONPATH"
} else {
Write-Output "`nPYTHONPATH already includes project root."
}
} else {
$env:PYTHONPATH = $PWD
Write-Output "`nPYTHONPATH set to: $env:PYTHONPATH"
}
}
switch ($task) {
"active" {
. .\venv\Scripts\Activate.ps1
Ensure-PythonPath
Write-Output "`nUsing Python in venv '$(Split-Path $env:VIRTUAL_ENV -Leaf)':"
python --version
}
"make" {
# remove any existing venv
if (Test-Path .\venv) { Remove-Item .\venv -Recurse -Force }
# if pyenv exists, pin it; otherwise verify system Python
if (Test-Path "$env:USERPROFILE\.pyenv") {
pyenv global $pythonVersion
Write-Output "Set pyenv global & local to Python $pythonVersion."
} else {
$sysVer = (& python --version 2>&1) -replace 'Python ', ''
if ($sysVer -eq $pythonVersion) {
Write-Output "System Python $sysVer matches required $pythonVersion."
} else {
Write-Warning "System Python is $sysVer; expected $pythonVersion. Please install or use pyenv-win."
}
}
# create & activate venv
python -m venv .\venv
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Virtual environment created." -ForegroundColor Green
} else {
Write-Host "❌ Failed to create virtual environment." -ForegroundColor Red
exit 1
}
. .\venv\Scripts\Activate.ps1
Ensure-PythonPath
Write-Output "`nUsing Python in venv '$(Split-Path $env:VIRTUAL_ENV -Leaf)':"
python --version
# install tooling & deps
python -m pip install --upgrade pip
python -m pip install "uv==$UV_VERSION"
uv lock
uv sync --active --locked --extra dev --extra docs
pre-commit install
}
"update" {
. .\venv\Scripts\Activate.ps1
Ensure-PythonPath
python -m pip install --upgrade pip
pip install --upgrade "uv==$UV_VERSION"
uv lock --upgrade
uv sync --active --locked --extra dev --extra docs
}
"audit" {
. .\venv\Scripts\Activate.ps1
Ensure-PythonPath
uv lock --check
uv export --locked --extra dev --no-emit-project -o requirements-audit.txt
uvx "pip-audit==$PIP_AUDIT_VERSION" -r requirements-audit.txt
Remove-Item -Force requirements-audit.txt
}
"test" {
pytest
}
"lint" {
ruff check . --fix --exit-non-zero-on-fix
ruff format
mypy .
}
"builddocs" {
Write-Host "📚 Building documentation..." -ForegroundColor Cyan
Push-Location docs
try {
sphinx-build -b html source build/html
Write-Host "✅ Documentation built in docs/build/html/" -ForegroundColor Green
}
catch {
Write-Host "❌ Documentation build failed: $_" -ForegroundColor Red
exit 1
}
finally {
Pop-Location
}
}
"servedocs" {
Write-Host "📚 Starting live documentation server..." -ForegroundColor Cyan
Push-Location docs
try {
Write-Host "🌐 Documentation server will run at http://127.0.0.1:8000" -ForegroundColor Yellow
Write-Host "Press Ctrl+C to stop the server" -ForegroundColor Yellow
sphinx-autobuild source build/html --host 127.0.0.1 --port 8000 --re-ignore ".*\..*"
}
catch {
Write-Host "❌ Failed to start documentation server: $_" -ForegroundColor Red
exit 1
}
finally {
Pop-Location
}
}
"clean" {
Write-Host "🧹 Cleaning documentation artifacts..." -ForegroundColor Cyan
if (Test-Path ".\docs\build") { Remove-Item ".\docs\build" -Recurse -Force }
if (Test-Path ".\docs\source\api\generated") { Remove-Item ".\docs\source\api\generated" -Recurse -Force }
. .\venv\Scripts\Activate.ps1
pre-commit uninstall
if ($env:VIRTUAL_ENV) {
& "$env:VIRTUAL_ENV\Scripts\deactivate.bat" 2>$null
}
if (Test-Path .\venv) {
Remove-Item .\venv -Recurse -Force
}
Write-Host "🧹 Clean complete." -ForegroundColor Green
}
default {
Write-Error "Invalid task '$task'. Use active, make, update, test, lint, audit, builddocs, servedocs, or clean."
exit 1
}
}
Pop-Location