Scripts: Make Start.bat idiotproof
Start now creates a venv, installs the correct requirements, and starts the API. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
060d422e03
commit
cc3229c109
3 changed files with 79 additions and 13 deletions
13
Start.bat
13
Start.bat
|
|
@ -1,13 +0,0 @@
|
|||
@echo off
|
||||
|
||||
set VENV_DIR=
|
||||
set REQUIREMENTS_FILE=
|
||||
|
||||
if not defined PYTHON (set PYTHON=python)
|
||||
if not defined VENV_DIR (set "VENV_DIR=%~dp0%venv")
|
||||
if not defined REQUIREMENTS_FILE (set "REQUIREMENTS_FILE=requirements-nowheel.txt")
|
||||
|
||||
call "%VENV_DIR%\Scripts\activate.bat"
|
||||
call pip -V
|
||||
if NOT [%1] == [--ignore-upgrade] call pip install --upgrade -r %REQUIREMENTS_FILE%
|
||||
call python main.py
|
||||
11
start.bat
Normal file
11
start.bat
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:: From https://github.com/jllllll/windows-venv-installers/blob/main/Powershell/run-ps-script.cmd
|
||||
@echo off
|
||||
|
||||
set SCRIPT_NAME=start.ps1
|
||||
|
||||
:: This will run the Powershell script named above in the current directory
|
||||
:: This is intended for systems who have not changed the script execution policy from default
|
||||
:: These systems will be unable to directly execute Powershell scripts unless done through CMD.exe like below
|
||||
|
||||
if not exist "%~dp0\%SCRIPT_NAME%" ( echo %SCRIPT_NAME% not found! && pause && goto eof )
|
||||
call powershell.exe -executionpolicy Bypass ". '%~dp0\start.ps1' %*"
|
||||
68
start.ps1
Normal file
68
start.ps1
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# Arg parsing
|
||||
param(
|
||||
[switch]$ignore_upgrade = $false,
|
||||
[switch]$activate_venv = $false
|
||||
)
|
||||
|
||||
# Gets the currently installed CUDA version
|
||||
function GetRequirementsFile {
|
||||
$GpuInfo = (Get-WmiObject Win32_VideoController).Name
|
||||
if ($GpuInfo.Contains("AMD")) {
|
||||
Write-Output "AMD/ROCm isn't supported on Windows. Please switch to linux."
|
||||
exit
|
||||
}
|
||||
|
||||
$CudaPath = $env:CUDA_PATH
|
||||
$CudaVersion = Split-Path $CudaPath -Leaf
|
||||
|
||||
# Decide requirements based on CUDA version
|
||||
if ($CudaVersion.Contains("12")) {
|
||||
return "requirements"
|
||||
} elseif ($CudaVersion.Contains("11.8")) {
|
||||
return "requirements-cu118"
|
||||
} else {
|
||||
Write-Output "Script cannot find your CUDA installation. installing from requirements-nowheel.txt"
|
||||
return "requirements-nowheel"
|
||||
}
|
||||
}
|
||||
|
||||
# Make a venv and enter it
|
||||
function CreateAndActivateVenv {
|
||||
# Is the user using conda?
|
||||
if ($null -ne $env:CONDA_PREFIX) {
|
||||
Write-Output "It looks like you're in a conda environment. Skipping venv check."
|
||||
return
|
||||
}
|
||||
|
||||
$VenvDir = "$PSScriptRoot\venv"
|
||||
|
||||
if (!(Test-Path -Path $VenvDir)) {
|
||||
Write-Output "Venv doesn't exist! Creating one for you."
|
||||
python -m venv venv
|
||||
}
|
||||
|
||||
. "$VenvDir\Scripts\activate.ps1"
|
||||
|
||||
if ($activate_venv) {
|
||||
Write-Output "Stopping at venv activation due to user request."
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
# Entrypoint for API start
|
||||
function StartAPI {
|
||||
pip -V
|
||||
if ($ignore_upgrade) {
|
||||
Write-Output "Ignoring pip dependency upgrade due to user request."
|
||||
} else {
|
||||
pip install --upgrade -r "$RequirementsFile.txt"
|
||||
}
|
||||
|
||||
python main.py
|
||||
}
|
||||
|
||||
# Navigate to the script directory
|
||||
Set-Location $PSScriptRoot
|
||||
$RequirementsFile = GetRequirementsFile
|
||||
CreateAndActivateVenv
|
||||
StartAPI
|
||||
Loading…
Add table
Add a link
Reference in a new issue