File size: 1,704 Bytes
15c46ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
param(
    [switch]$Install,
    [switch]$CheckOnly
)
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path -Parent $PSScriptRoot
$runtimePath = Join-Path $projectRoot '.runtime'
$pythonPath = Join-Path $runtimePath 'python.exe'
Push-Location $projectRoot
try {
    if (-not (Test-Path -LiteralPath $pythonPath)) {
        if (-not $Install) { throw 'Runtime missing. Run this script with -Install first.' }
        $condaCommand = Get-Command conda -ErrorAction Stop
        & $condaCommand create --prefix $runtimePath python=3.10 pip -y
        if ($LASTEXITCODE -ne 0) { throw 'Conda environment creation failed.' }
    }
    if ($Install) {
        & $pythonPath -m pip install pip==24.3.1 setuptools==69.5.1 wheel==0.44.0
        if ($LASTEXITCODE -ne 0) { throw 'Build tools installation failed.' }
        & $pythonPath -m pip install torch==1.13.1+cpu torchvision==0.14.1+cpu torchaudio==0.13.1+cpu --extra-index-url https://download.pytorch.org/whl/cpu
        if ($LASTEXITCODE -ne 0) { throw 'CPU PyTorch installation failed.' }
        & $pythonPath -m pip install -r requirements.txt
        if ($LASTEXITCODE -ne 0) { throw 'Runtime dependencies installation failed.' }
        & $pythonPath -m pip check
        if ($LASTEXITCODE -ne 0) { throw 'Dependency validation failed.' }
    }
    if ($CheckOnly) {
        & $pythonPath -X utf8 scripts/check_environment.py
        if ($LASTEXITCODE -ne 0) { throw 'Environment check failed.' }
    } else {
        # start-preview.cmd scopes these environment settings with setlocal.
        & (Join-Path $projectRoot 'start-preview.cmd')
        if ($LASTEXITCODE -ne 0) { throw 'CPU preview failed.' }
    }
} finally {
    Pop-Location
}