Repository navigation
Expand file tree
/
Copy pathuninstall.ps1
More file actions
243 lines (217 loc) · 11 KB
/
Copy pathuninstall.ps1
File metadata and controls
243 lines (217 loc) · 11 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
# uninstall.ps1 - Uninstaller for interpreter-v2
# Usage: powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/bquenin/interpreter/main/uninstall.ps1 | iex"
$ErrorActionPreference = 'Stop'
Write-Host ""
Write-Host "=== interpreter-v2 Uninstaller ===" -ForegroundColor Cyan
Write-Host ""
function Remove-InterpreterPath {
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter(Mandatory = $true)]
[string]$Description
)
if (-not (Test-Path -LiteralPath $Path)) {
return
}
try {
Remove-Item -LiteralPath $Path -Recurse -Force
Write-Host " Removed $Description" -ForegroundColor Green
} catch {
Write-Host " Could not remove $Description`: $($_.Exception.Message)" -ForegroundColor Red
}
}
# A custom install location (see install.ps1) holds the tool environment, the
# uv-managed Python, and the model cache. INTERPRETER_HOME wins over the pointer
# file the installer wrote, matching the app and the installer.
$configDir = Join-Path $env:USERPROFILE ".interpreter"
$installRootFile = Join-Path $configDir "install-dir"
$installRoot = $null
if ($env:INTERPRETER_HOME -and $env:INTERPRETER_HOME.Trim()) {
$installRoot = $env:INTERPRETER_HOME.Trim()
} elseif (Test-Path -LiteralPath $installRootFile -PathType Leaf) {
$installRoot = (Get-Content -LiteralPath $installRootFile -Raw).Trim()
if (-not $installRoot) { $installRoot = $null }
}
if ($installRoot) {
$installRoot = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($installRoot).TrimEnd('\')
$env:UV_TOOL_DIR = Join-Path $installRoot "uv\tools"
$env:UV_PYTHON_INSTALL_DIR = Join-Path $installRoot "uv\python"
Write-Host "Install location: $installRoot" -ForegroundColor Gray
Write-Host ""
}
# uv's installer adds itself to ~/.local/bin. Look there as a fallback because
# the current shell may not have picked up the PATH change yet.
$uvCommand = Get-Command uv -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
$uvExecutable = if ($uvCommand) { $uvCommand.Source } else { $null }
$defaultUvExecutable = Join-Path $env:USERPROFILE ".local\bin\uv.exe"
if (-not $uvExecutable -and (Test-Path -LiteralPath $defaultUvExecutable -PathType Leaf)) {
$uvExecutable = $defaultUvExecutable
}
# Resolve uv's configured directories when possible, while retaining defaults
# for interrupted uv installs or environments that are no longer registered.
$toolRoot = if ($env:UV_TOOL_DIR) { $env:UV_TOOL_DIR } else { Join-Path $env:APPDATA "uv\tools" }
$toolBin = if ($env:UV_TOOL_BIN_DIR) { $env:UV_TOOL_BIN_DIR } else { Join-Path $env:USERPROFILE ".local\bin" }
if ($uvExecutable) {
$reportedToolRoot = & $uvExecutable tool dir 2>$null
if ($LASTEXITCODE -eq 0 -and $reportedToolRoot) {
$toolRoot = ($reportedToolRoot | Select-Object -Last 1).Trim()
}
$reportedToolBin = & $uvExecutable tool dir --bin 2>$null
if ($LASTEXITCODE -eq 0 -and $reportedToolBin) {
$toolBin = ($reportedToolBin | Select-Object -Last 1).Trim()
}
}
$toolEnvironment = Join-Path $toolRoot "interpreter-v2"
$toolExecutable = Join-Path $toolBin "interpreter-v2.exe"
Write-Host "[1/5] Uninstalling interpreter-v2..." -ForegroundColor Yellow
if ($uvExecutable) {
$toolList = & $uvExecutable tool list 2>$null
if ($toolList -match "interpreter-v2" -or (Test-Path -LiteralPath $toolEnvironment)) {
$ErrorActionPreference = 'Continue'
& $uvExecutable tool uninstall interpreter-v2
$uninstallExitCode = $LASTEXITCODE
$ErrorActionPreference = 'Stop'
if ($uninstallExitCode -eq 0) {
Write-Host " interpreter-v2 uninstalled" -ForegroundColor Green
} else {
Write-Host " uv could not uninstall the tool; cleaning up its files directly" -ForegroundColor Yellow
}
} else {
Write-Host " interpreter-v2 is not registered with uv" -ForegroundColor Gray
}
} else {
Write-Host " uv was not found; cleaning up its files directly" -ForegroundColor Yellow
}
# Remove orphan files left by an interrupted install or a stale uv registry.
Write-Host "[2/5] Cleaning up orphan files..." -ForegroundColor Yellow
if (Test-Path -LiteralPath $toolExecutable) {
Remove-InterpreterPath -Path $toolExecutable -Description "orphan executable"
} else {
Write-Host " No orphan executable found" -ForegroundColor Gray
}
if (Test-Path -LiteralPath $toolEnvironment) {
Remove-InterpreterPath -Path $toolEnvironment -Description "stale tool environment"
} else {
Write-Host " No stale tool environment found" -ForegroundColor Gray
}
# An install that was later moved to a custom location may have left the
# default environment behind.
$defaultToolEnvironment = Join-Path $env:APPDATA "uv\tools\interpreter-v2"
if ($installRoot -and (Test-Path -LiteralPath $defaultToolEnvironment)) {
Remove-InterpreterPath -Path $defaultToolEnvironment -Description "tool environment left in the user profile"
}
# New installers use this dedicated cache so it can always be removed without
# disturbing other uv users. Older installers used uv's shared cache; prune only
# entries uv knows are unreachable and leave reusable downloads alone.
Write-Host "[3/5] Removing package downloads..." -ForegroundColor Yellow
$installCacheDir = Join-Path $env:LOCALAPPDATA "interpreter-v2\uv-cache"
if (Test-Path -LiteralPath $installCacheDir) {
Remove-InterpreterPath -Path $installCacheDir -Description "interpreter package cache"
}
if ($uvExecutable) {
$ErrorActionPreference = 'Continue'
& $uvExecutable cache prune
$pruneExitCode = $LASTEXITCODE
$ErrorActionPreference = 'Stop'
if ($pruneExitCode -eq 0) {
Write-Host " Unreachable uv cache entries removed" -ForegroundColor Green
} else {
Write-Host " Some uv cache entries could not be removed; close other uv processes and retry" -ForegroundColor Red
}
$sharedCacheDir = & $uvExecutable cache dir 2>$null
if ($LASTEXITCODE -eq 0 -and $sharedCacheDir) {
$sharedCacheDir = ($sharedCacheDir | Select-Object -Last 1).Trim()
Write-Host " Older installers may have left reusable downloads in uv's shared cache:" -ForegroundColor Gray
Write-Host " $sharedCacheDir" -ForegroundColor Gray
Write-Host " Run 'uv cache clean' to clear it, including downloads cached by other uv projects." -ForegroundColor Gray
}
} else {
$defaultCacheDir = if ($env:UV_CACHE_DIR) { $env:UV_CACHE_DIR } else { Join-Path $env:LOCALAPPDATA "uv\cache" }
Write-Host " uv was not found, so its cache could not be pruned" -ForegroundColor Yellow
Write-Host " To clear every uv download later, reinstall uv and run 'uv cache clean': $defaultCacheDir" -ForegroundColor Gray
}
# Remove user data
Write-Host "[4/5] Removing user data..." -ForegroundColor Yellow
if ($env:HF_HUB_CACHE) {
$modelsDir = $env:HF_HUB_CACHE
} elseif ($env:HF_HOME) {
$modelsDir = Join-Path $env:HF_HOME "hub"
} elseif ($env:XDG_CACHE_HOME) {
$modelsDir = Join-Path $env:XDG_CACHE_HOME "huggingface\hub"
} else {
$modelsDir = Join-Path $env:USERPROFILE ".cache\huggingface\hub"
}
# Remove config
if (Test-Path -LiteralPath $configDir) {
Remove-InterpreterPath -Path $configDir -Description "config directory"
} else {
Write-Host " Config directory not found" -ForegroundColor Gray
}
# Remove the repositories actually downloaded by interpreter-v2. Retain the
# legacy bquenin pattern for caches created by older releases. With a custom
# install location the models live under it and are removed below, but an
# install that was moved there later may have left models in this cache.
$modelCacheNames = @(
"models--rtr46--meiki.text.detect.v0",
"models--rtr46--meiki.txt.recognition.v0",
"models--entai2965--sugoi-v4-ja-en-ctranslate2"
)
$removedModel = $false
if (Test-Path -LiteralPath $modelsDir -PathType Container) {
foreach ($modelCacheName in $modelCacheNames) {
$modelPath = Join-Path $modelsDir $modelCacheName
if (Test-Path -LiteralPath $modelPath) {
Remove-InterpreterPath -Path $modelPath -Description $modelCacheName
$removedModel = $true
}
$modelLockPath = Join-Path (Join-Path $modelsDir ".locks") $modelCacheName
if (Test-Path -LiteralPath $modelLockPath) {
Remove-InterpreterPath -Path $modelLockPath -Description "$modelCacheName lock files"
}
}
$legacyModels = Get-ChildItem -LiteralPath $modelsDir -Directory -Filter "models--bquenin--*" -ErrorAction SilentlyContinue
foreach ($legacyModel in $legacyModels) {
Remove-InterpreterPath -Path $legacyModel.FullName -Description $legacyModel.Name
$removedModel = $true
}
$legacyLocksDir = Join-Path $modelsDir ".locks"
if (Test-Path -LiteralPath $legacyLocksDir -PathType Container) {
$legacyModelLocks = Get-ChildItem -LiteralPath $legacyLocksDir -Directory -Filter "models--bquenin--*" -ErrorAction SilentlyContinue
foreach ($legacyModelLock in $legacyModelLocks) {
Remove-InterpreterPath -Path $legacyModelLock.FullName -Description "$($legacyModelLock.Name) lock files"
}
}
}
if (-not $removedModel) {
Write-Host " Cached models not found" -ForegroundColor Gray
}
# Remove the custom install location. Only the folders the installer creates
# are deleted, only when the installer's marker file proves it created this
# root, and the root itself only once it is empty. A mistyped INTERPRETER_HOME
# or a root shared with other files is never wiped wholesale.
Write-Host "[5/5] Removing install location..." -ForegroundColor Yellow
$installMarker = if ($installRoot) { Join-Path $installRoot ".interpreter-v2" } else { $null }
if (-not $installRoot) {
Write-Host " No custom install location" -ForegroundColor Gray
} elseif (-not (Test-Path -LiteralPath $installMarker -PathType Leaf)) {
Write-Host " $installRoot was not created by the interpreter-v2 installer; leaving it alone" -ForegroundColor Yellow
} else {
Remove-InterpreterPath -Path (Join-Path $installRoot "uv") -Description "tool environment and Python"
Remove-InterpreterPath -Path (Join-Path $installRoot "uv-cache") -Description "interpreter package cache"
Remove-InterpreterPath -Path (Join-Path $installRoot "models") -Description "downloaded models"
Remove-Item -LiteralPath $installMarker -Force -ErrorAction SilentlyContinue
if (Test-Path -LiteralPath $installRoot -PathType Container) {
$leftovers = Get-ChildItem -LiteralPath $installRoot -Force -ErrorAction SilentlyContinue
if ($leftovers) {
Write-Host " Kept $installRoot because it still contains other files" -ForegroundColor Gray
} else {
Remove-InterpreterPath -Path $installRoot -Description "install location $installRoot"
}
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host " Uninstall complete!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""