罗广辉
10 hours ago 7cc239cee1a9af4e2e8a0f3d5b7a00a074b17214
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
param(
    [string]$Capability = ""
)
 
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
$PythonCandidates = @(
    (Join-Path $env:LOCALAPPDATA "Programs/Python/Python312/python.exe"),
    (Join-Path $env:LOCALAPPDATA "Programs/Python/Python311/python.exe"),
    (Join-Path $env:ProgramFiles "Python312/python.exe"),
    (Join-Path $env:ProgramFiles "Python311/python.exe")
)
$PythonExe = $PythonCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
 
if (-not $PythonExe) {
    throw "Python 3.11 or 3.12 was not found. Install the 64-bit Windows version first."
}
 
$PythonVersion = & $PythonExe --version
Write-Host "Using $PythonVersion at $PythonExe"
 
if ($Capability) {
    $CapabilityDir = Join-Path $Root "capabilities/$Capability"
    if (-not (Test-Path $CapabilityDir)) {
        throw "Unknown capability: $Capability"
    }
    $Requirements = Join-Path $CapabilityDir "requirements.txt"
} else {
    $Requirements = Join-Path $Root "requirements/dev.txt"
}
 
if ($Capability) {
    $Venv = Join-Path $Root ".venvs/$Capability"
} else {
    $Venv = Join-Path $Root ".venv"
}
 
if (-not (Test-Path $Venv)) {
    & $PythonExe -m venv $Venv
}
 
$VenvPython = Join-Path $Venv "Scripts/python.exe"
& $VenvPython -m pip install --upgrade pip
& $VenvPython -m pip install -r $Requirements
& $VenvPython -m pip install -e $Root
 
Write-Host "Environment ready: $Venv"