forked from OpenFAST/openfast_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_student_env.ps1
More file actions
68 lines (56 loc) · 2.08 KB
/
setup_student_env.ps1
File metadata and controls
68 lines (56 loc) · 2.08 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
param(
[string]$EnvName = "openfast-toolbox-env",
[string]$CondaExe = "conda"
)
$ErrorActionPreference = "Stop"
function Invoke-Conda {
param(
[Parameter(Mandatory = $true)]
[string[]]$Args
)
& $CondaExe @Args
if ($LASTEXITCODE -ne 0) {
throw "Conda command failed: $CondaExe $($Args -join ' ')"
}
}
Write-Host "Repository root: $PSScriptRoot\.."
Write-Host "Environment name: $EnvName"
Write-Host "Conda executable : $CondaExe"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$envFile = Join-Path $repoRoot "environment.yml"
if (-not (Test-Path $envFile)) {
throw "environment.yml not found at: $envFile"
}
Write-Host ""
Write-Host "Creating or updating conda environment from environment.yml..."
Invoke-Conda -Args @("env", "update", "--name", $EnvName, "--file", $envFile, "--prune")
$pythonExe = Join-Path (Split-Path (Split-Path $CondaExe -Parent) -Parent) ("envs\" + $EnvName + "\python.exe")
if (-not (Test-Path $pythonExe)) {
Write-Host "Could not infer python.exe from Conda path. Falling back to 'python' after activation is left to the user."
Write-Host "Run manually:"
Write-Host " conda activate $EnvName"
Write-Host " python -m pip install -e ."
Write-Host " python -m ipykernel install --user --name $EnvName --display-name `"$EnvName`""
exit 0
}
Write-Host ""
Write-Host "Installing editable openfast_toolbox package..."
& $pythonExe -m pip install -e $repoRoot
if ($LASTEXITCODE -ne 0) {
throw "Editable install failed."
}
Write-Host ""
Write-Host "Registering Jupyter kernel..."
& $pythonExe -m ipykernel install --user --name $EnvName --display-name $EnvName
if ($LASTEXITCODE -ne 0) {
throw "Kernel registration failed."
}
Write-Host ""
Write-Host "Running verification import..."
& $pythonExe -c "import openfast_toolbox, numpy, pandas, matplotlib; print('Python environment OK')"
if ($LASTEXITCODE -ne 0) {
throw "Verification import failed."
}
Write-Host ""
Write-Host "Setup completed successfully."
Write-Host "Next step: activate the environment and verify OpenFAST.exe is available."