From df6ca4d1275e476068310309c519df183a65985c Mon Sep 17 00:00:00 2001 From: em411 <7682404+em411@users.noreply.github.com> Date: Sun, 1 Oct 2023 20:49:49 +0200 Subject: [PATCH 1/6] feat: implement ps1 launcher --- webui.ps1 | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 webui.ps1 diff --git a/webui.ps1 b/webui.ps1 new file mode 100644 index 000000000..1ec571582 --- /dev/null +++ b/webui.ps1 @@ -0,0 +1,77 @@ +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" } + +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" + . ShowStdOutStdErr + exit +} + +try { + & $PYTHON -m pip --help 2>tmp\stderr.txt | Out-File tmp\stdout.txt +} +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" + . 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)" + 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 { + 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 (Test-Path $ACCELERATE) { + Write-Output "Using accelerate" + & $ACCELERATE launch --num_cpu_threads_per_process=6 launch.py $args + } +} +else { + & $PYTHON launch.py $args +} + +Pause 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 2/6] 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 } From 874e9ecc556741db568ae4ac6ba117639c3dcead Mon Sep 17 00:00:00 2001 From: em411 <7682404+em411@users.noreply.github.com> Date: Sun, 1 Oct 2023 21:09:22 +0200 Subject: [PATCH 3/6] chore: update wiki guide with new ps1 launcher --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 19318a2eb..9d8cd1851 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Additional models will be added as they become available and there is public int ### Run -Once SD.Next is installed, simply run `webui.bat` (*Windows*) or `webui.sh` (*Linux or MacOS*) +Once SD.Next is installed, simply run `webui.ps1` (*Windows*) or `webui.sh` (*Linux or MacOS*) Below is partial list of all available parameters, run `webui --help` for the full list: From e027d57e8270eaf491a80a885be8671be5c51c69 Mon Sep 17 00:00:00 2001 From: em411 <7682404+em411@users.noreply.github.com> Date: Sun, 1 Oct 2023 21:09:53 +0200 Subject: [PATCH 4/6] chore: add deprecation message --- webui.bat | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/webui.bat b/webui.bat index 2d12762c6..1b2e3f754 100755 --- a/webui.bat +++ b/webui.bat @@ -1,5 +1,20 @@ @echo off +echo. +echo ****************************************************************** +echo ** DEPRECATION WARNING ** +echo ** ** +echo ** This Batch (.bat) version of the script is now deprecated ** +echo ** and will be removed in the future. ** +echo ** ** +echo ** Please use the new PowerShell (.ps1) script: "webui.ps1" ** +echo ** ** +echo ****************************************************************** +echo. + +:: Allow the user to read the deprecation warning before proceeding +timeout /t 10 + if not defined PYTHON (set PYTHON=python) if not defined VENV_DIR (set "VENV_DIR=%~dp0%venv") set ERROR_REPORTING=FALSE From 43cdbbe473d3143e8771228810ca516a5c9c3719 Mon Sep 17 00:00:00 2001 From: em411 <7682404+em411@users.noreply.github.com> Date: Mon, 2 Oct 2023 08:32:53 +0200 Subject: [PATCH 5/6] Revert "chore: update wiki guide with new ps1 launcher" This reverts commit 874e9ecc556741db568ae4ac6ba117639c3dcead. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d8cd1851..19318a2eb 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Additional models will be added as they become available and there is public int ### Run -Once SD.Next is installed, simply run `webui.ps1` (*Windows*) or `webui.sh` (*Linux or MacOS*) +Once SD.Next is installed, simply run `webui.bat` (*Windows*) or `webui.sh` (*Linux or MacOS*) Below is partial list of all available parameters, run `webui --help` for the full list: From fbbad2945be24a4005b912030526d0c58b968189 Mon Sep 17 00:00:00 2001 From: em411 <7682404+em411@users.noreply.github.com> Date: Mon, 2 Oct 2023 08:34:01 +0200 Subject: [PATCH 6/6] Revert "chore: add deprecation message" This reverts commit e027d57e8270eaf491a80a885be8671be5c51c69. --- webui.bat | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/webui.bat b/webui.bat index 1b2e3f754..2d12762c6 100755 --- a/webui.bat +++ b/webui.bat @@ -1,20 +1,5 @@ @echo off -echo. -echo ****************************************************************** -echo ** DEPRECATION WARNING ** -echo ** ** -echo ** This Batch (.bat) version of the script is now deprecated ** -echo ** and will be removed in the future. ** -echo ** ** -echo ** Please use the new PowerShell (.ps1) script: "webui.ps1" ** -echo ** ** -echo ****************************************************************** -echo. - -:: Allow the user to read the deprecation warning before proceeding -timeout /t 10 - if not defined PYTHON (set PYTHON=python) if not defined VENV_DIR (set "VENV_DIR=%~dp0%venv") set ERROR_REPORTING=FALSE