forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathensureuv.ps1
More file actions
118 lines (106 loc) · 2.67 KB
/
ensureuv.ps1
File metadata and controls
118 lines (106 loc) · 2.67 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
[CmdletBinding()]
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$UvArgs
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
[Version]$UvVersion = '0.7.9'
function Invoke-Uv {
& uv @UvArgs
exit $LASTEXITCODE
}
function Install-Uv {
param(
[Switch]$IsUpdate
)
$installAction = if ($IsUpdate) { 'Update' } else { 'Install' }
$hasWinGet = [bool](Get-Command winget -ErrorAction SilentlyContinue)
if ($IsUpdate) {
Write-Host 'Uv is out of date.'
}
else {
Write-Host 'Uv is not installed.'
}
Write-Host ''
Write-Host "Choose how to $($installAction.ToLower()) uv:"
while ($true) {
if ($hasWinGet) {
Write-Host "[1] $installAction using WinGet (recommended)"
}
else {
Write-Host 'WinGet is NOT available.'
}
Write-Host "[2] $installAction using the official uv install script"
Write-Host '[0] Exit'
$choice = Read-Host 'Enter your choice'
switch ($choice) {
'0' { exit }
'1' {
if (-not $hasWinGet) {
Write-Warning 'WinGet is not available. Please choose another option.'
continue
}
$WinGetArgs = @('--accept-source-agreements', '--disable-interactivity' , '-e', 'astral-sh.uv')
try {
if ($IsUpdate) {
Write-Host 'Updating uv using WinGet...'
& winget update @WinGetArgs
}
else {
Write-Host 'Installing uv using WinGet...'
& winget install $WinGetArgs
}
if ($LASTEXITCODE -ne 0) {
throw "winget command failed with exit code $LASTEXITCODE"
}
return
}
catch {
Write-Error "Failed to $($installAction.ToLower()) uv using WinGet: $_"
}
}
'2' {
try {
Write-Host 'Installing uv using the official script...'
Invoke-RestMethod https://astral.sh/uv/install.ps1 | Invoke-Expression
$env:PATH = "$(Join-Path $env:USERPROFILE '.local bin');$env:PATH"
return
}
catch {
Write-Error "Failed to install uv via the official script: $_"
}
}
default {
Write-Warning "Invalid choice: '$choice'. Please try again."
}
}
}
}
# Main Script Logic
$hasUv = [bool](Get-Command uv -ErrorAction SilentlyContinue)
if ($hasUv) {
try {
$json = uv self version --output-format json | ConvertFrom-Json
[Version]$installedVersion = $json.Version
}
catch {
Write-Warning 'Could not retrieve uv version.'
[Version]$installedVersion = '0.0.0'
}
if ($installedVersion -ge $UvVersion) {
Invoke-Uv
}
else {
Write-Host "uv version $installedVersion is installed, but version $UvVersion or higher is required. Trying to update..."
uv self update
if ($LASTEXITCODE -ne 0) {
Write-Warning 'Prompting for manual install/update.'
Install-Uv -IsUpdate
}
}
}
else {
Install-Uv
}
Invoke-Uv