-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1.6.GUI.ps1
More file actions
118 lines (102 loc) · 3.4 KB
/
Copy path1.6.GUI.ps1
File metadata and controls
118 lines (102 loc) · 3.4 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(
[int]$Port = 7788,
[string]$BindHost = "127.0.0.1",
[switch]$Cloud,
[switch]$Native,
[switch]$NoBrowser,
[switch]$NoPause
)
$ErrorActionPreference = "Stop"
$ProjectRoot = (Resolve-Path -LiteralPath $PSScriptRoot).Path
$GuiDir = Join-Path $ProjectRoot "gui"
$LaunchScript = Join-Path $GuiDir "launch.py"
if (-not (Test-Path -LiteralPath $LaunchScript -PathType Leaf)) {
Write-Host "GUI launcher was not found under $GuiDir" -ForegroundColor Red
if (-not $NoPause) {
Read-Host "Press Enter to exit" | Out-Null
}
exit 1
}
$LaunchScript = (Resolve-Path -LiteralPath $LaunchScript).Path
Set-Location $GuiDir
function Exit-WithError {
param([string]$Message)
Write-Host $Message -ForegroundColor Red
if (-not $NoPause) {
Read-Host "Press Enter to exit" | Out-Null
}
exit 1
}
function Resolve-ProjectPython {
$candidates = @(
(Join-Path $ProjectRoot ".venv\Scripts\python.exe"),
(Join-Path $ProjectRoot "venv\Scripts\python.exe"),
(Join-Path $ProjectRoot ".venv/bin/python"),
(Join-Path $ProjectRoot "venv/bin/python")
)
foreach ($candidate in $candidates) {
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
return (Resolve-Path -LiteralPath $candidate).Path
}
}
if ($env:VIRTUAL_ENV) {
$activeCandidates = @(
(Join-Path $env:VIRTUAL_ENV "Scripts\python.exe"),
(Join-Path $env:VIRTUAL_ENV "bin/python")
)
foreach ($candidate in $activeCandidates) {
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
return (Resolve-Path -LiteralPath $candidate).Path
}
}
}
return $null
}
$PythonExe = Resolve-ProjectPython
if (-not $PythonExe) {
Exit-WithError "Project virtual environment was not found. From $ProjectRoot run: uv sync --extra cu130 --extra gui --extra lycoris --extra attention --index-strategy unsafe-best-match"
}
$PythonDir = Split-Path -Parent $PythonExe
$VenvDir = Split-Path -Parent $PythonDir
$Env:VIRTUAL_ENV = $VenvDir
$Env:PATH = "$PythonDir$([System.IO.Path]::PathSeparator)$Env:PATH"
Write-Host "Using project Python: $PythonExe" -ForegroundColor Cyan
Write-Host "Virtual environment: $VenvDir" -ForegroundColor Cyan
$Env:MUSUBI_GUI_PORT = [string]$Port
try {
& $PythonExe -c "import nicegui; import sys; print(sys.version); print(sys.executable)"
if ($LASTEXITCODE -ne 0) {
throw "nicegui import failed"
}
}
catch {
Exit-WithError "Project virtual environment is missing NiceGUI. From $ProjectRoot run: uv sync --extra cu130 --extra gui --extra lycoris --extra attention --index-strategy unsafe-best-match"
}
$launchArgs = @($LaunchScript, "--port=$Port")
if ($Cloud) {
$launchArgs += "--cloud"
}
elseif ($BindHost -and $BindHost -ne "0.0.0.0") {
$launchArgs += "--host=$BindHost"
}
if ($Native) {
$launchArgs += "--native"
}
if ($NoBrowser) {
$launchArgs += "--no-browser"
}
Write-Host "Starting NiceGUI launcher (preferred port: $Port)..." -ForegroundColor Green
if ($Native) {
Write-Host "Mode: Native window" -ForegroundColor Cyan
}
else {
Write-Host "Mode: Web browser" -ForegroundColor Cyan
}
Write-Host "Launch args: $($launchArgs -join ' ')" -ForegroundColor DarkGray
& $PythonExe @launchArgs
$exitCode = $LASTEXITCODE
if (-not $NoPause) {
Read-Host "Press Enter to exit" | Out-Null
}
exit $exitCode