From 50a7fbb9ef57e81f0fdf143a98c8810a4197e0b5 Mon Sep 17 00:00:00 2001 From: em411 <7682404+em411@users.noreply.github.com> Date: Sun, 1 Oct 2023 21:08:46 +0200 Subject: [PATCH] style: improve code style --- webui.ps1 | 56 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/webui.ps1 b/webui.ps1 index 1ec571582..eac963fea 100644 --- a/webui.ps1 +++ b/webui.ps1 @@ -1,76 +1,84 @@ function ShowStdOutStdErr { Write-Output "exit code: $LASTEXITCODE" + if ((Get-Item tmp\stdout.txt).Length -ne 0) { Write-Output "`nstdout:" Get-Content tmp\stdout.txt } + if ((Get-Item tmp\stderr.txt).Length -ne 0) { Write-Error "`nstderr:" Get-Content tmp\stderr.txt } + Write-Output "`nLaunch Failed" Pause } -$PYTHON = if ($env:PYTHON) { $env:PYTHON } else { "python" } -$VENV_DIR = if ($env:VENV_DIR) { $env:VENV_DIR } else { Join-Path $PSScriptRoot "venv" } +$PYTHON = if ($env:PYTHON) { $env:PYTHON } else { 'python' } +$VENV_DIR = if ($env:VENV_DIR) { $env:VENV_DIR } else { Join-Path $PSScriptRoot 'venv' } -New-Item -Path "tmp" -ItemType Directory -ErrorAction SilentlyContinue +New-Item -Path 'tmp' -ItemType Directory -ErrorAction SilentlyContinue try { - & $PYTHON -c "" 2>tmp\stderr.txt | Out-File tmp\stdout.txt -} -catch { - Write-Output "Cannot launch python" + & $PYTHON -c '' 2>tmp\stderr.txt | Out-File tmp\stdout.txt +} catch { + Write-Output 'Cannot launch python' . ShowStdOutStdErr + exit } try { & $PYTHON -m pip --help 2>tmp\stderr.txt | Out-File tmp\stdout.txt -} -catch { +} catch { if (!$env:PIP_INSTALLER_LOCATION) { . ShowStdOutStdErr + exit } + & $PYTHON $env:PIP_INSTALLER_LOCATION 2>tmp\stderr.txt | Out-File tmp\stdout.txt + if ($LASTEXITCODE -ne 0) { - Write-Output "Cannot install pip" + Write-Output 'Cannot install pip' . ShowStdOutStdErr exit } } -if ($VENV_DIR -ne "-" -and $env:SKIP_VENV -ne "1") { - if (Test-Path (Join-Path $VENV_DIR "Scripts\Python.exe")) { - $PYTHON = Join-Path $VENV_DIR "Scripts\Python.exe" - } - else { - $PYTHON_FULLNAME = & $PYTHON -c "import sys; print(sys.executable)" +if ($VENV_DIR -ne '-' -and $env:SKIP_VENV -ne '1') { + if (Test-Path (Join-Path $VENV_DIR 'Scripts\Python.exe')) { + $PYTHON = Join-Path $VENV_DIR 'Scripts\Python.exe' + } else { + $PYTHON_FULLNAME = & $PYTHON -c 'import sys; print(sys.executable)' + Write-Output "Using python: $PYTHON_FULLNAME" Write-Output "Creating VENV: $VENV_DIR" + & $PYTHON_FULLNAME -m venv $VENV_DIR 2>tmp\stderr.txt | Out-File tmp\stdout.txt + if ($LASTEXITCODE -eq 0) { - $PYTHON = Join-Path $VENV_DIR "Scripts\Python.exe" - } - else { + $PYTHON = Join-Path $VENV_DIR 'Scripts\Python.exe' + } else { Write-Output "Failed creating VENV: '$VENV_DIR'" . ShowStdOutStdErr + exit } } + Write-Output "Using VENV: $VENV_DIR" } -if ($env:ACCELERATE -eq "True") { - $ACCELERATE = Join-Path $VENV_DIR "Scripts\accelerate.exe" +if ($env:ACCELERATE -eq 'True') { + $ACCELERATE = Join-Path $VENV_DIR 'Scripts\accelerate.exe' + if (Test-Path $ACCELERATE) { - Write-Output "Using accelerate" + Write-Output 'Using accelerate' & $ACCELERATE launch --num_cpu_threads_per_process=6 launch.py $args } -} -else { +} else { & $PYTHON launch.py $args }