-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.ps1
More file actions
76 lines (63 loc) · 2.19 KB
/
Copy pathsetup.ps1
File metadata and controls
76 lines (63 loc) · 2.19 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Setup script for Windows using venv
# This script sets up the Python environment and installs dependencies for FLM testing
#
# Behavior:
# - Creates a virtual environment using Python's built-in venv
# - If requirements.txt exists, installs packages with pip
# - Supports -Force to recreate the environment
param(
[switch]$Force
)
$ErrorActionPreference = "Stop"
Write-Host "Setting up FLM test environment for Windows..." -ForegroundColor Green
function Fail($Message) {
Write-Host "Error: $Message" -ForegroundColor Red
exit 1
}
function Warn($Message) {
Write-Host "Warning: $Message" -ForegroundColor Yellow
}
# Check if Python is available
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCmd) {
Fail "Python is not installed or not in PATH. Install Python 3.x from https://www.python.org/downloads/"
}
try {
$pythonVersion = python --version
Write-Host "Using $pythonVersion"
} catch {
Fail "Python was found, but 'python --version' failed."
}
$requirementsFile = "requirements.txt"
$venvPath = "venv"
if ($Force -and (Test-Path $venvPath)) {
Write-Host "Removing existing virtual environment at $venvPath..."
Remove-Item -Recurse -Force $venvPath
}
if (-not (Test-Path $venvPath)) {
Write-Host "Creating virtual environment..."
python -m venv $venvPath
if ($LASTEXITCODE -ne 0) {
Fail "Failed to create virtual environment."
}
} else {
Write-Host "Virtual environment already exists at $venvPath."
}
Write-Host "Activating virtual environment..."
& ".\$venvPath\Scripts\Activate.ps1"
if (Test-Path $requirementsFile) {
Write-Host "Installing Python packages from $requirementsFile..."
pip install -r $requirementsFile
if ($LASTEXITCODE -ne 0) {
Fail "Failed to install requirements from $requirementsFile."
}
} else {
Warn "$requirementsFile not found. Skipping package installation."
}
Write-Host "Setup complete!" -ForegroundColor Green
Write-Host ""
Write-Host "To activate the virtual environment in future sessions, run:" -ForegroundColor Cyan
Write-Host ".\$venvPath\Scripts\Activate.ps1"
Write-Host ""
Write-Host "To run tests, use:" -ForegroundColor Cyan
Write-Host "python main.py --help"