forked from ddxfish/sapphire
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.ps1
More file actions
69 lines (57 loc) · 1.67 KB
/
Copy pathrun.ps1
File metadata and controls
69 lines (57 loc) · 1.67 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
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $repoRoot
function Test-Command($name) {
return $null -ne (Get-Command $name -ErrorAction SilentlyContinue)
}
function Find-Conda {
$candidates = @(
"conda",
"$env:USERPROFILE\miniconda3\condabin\conda.bat",
"$env:USERPROFILE\anaconda3\condabin\conda.bat",
"$env:USERPROFILE\Miniconda3\condabin\conda.bat",
"$env:USERPROFILE\Anaconda3\condabin\conda.bat",
"C:\ProgramData\miniconda3\condabin\conda.bat",
"C:\ProgramData\Miniconda3\condabin\conda.bat"
)
foreach ($candidate in $candidates) {
if ($candidate -eq "conda") {
if (Test-Command "conda") { return "conda" }
continue
}
if (Test-Path $candidate) { return $candidate }
}
return $null
}
if ($env:VIRTUAL_ENV -or $env:CONDA_PREFIX) {
& python main.py
exit $LASTEXITCODE
}
$conda = Find-Conda
if ($conda) {
& $conda run -n sani python main.py
if ($LASTEXITCODE -eq 0) {
exit 0
}
}
if (Test-Command "py") {
& py -3 main.py
exit $LASTEXITCODE
}
if (Test-Command "python") {
& python main.py
exit $LASTEXITCODE
}
$pythonCandidates = @(
"$env:USERPROFILE\anaconda3\python.exe",
"$env:USERPROFILE\miniconda3\python.exe",
"$env:USERPROFILE\Anaconda3\python.exe",
"$env:USERPROFILE\Miniconda3\python.exe"
)
foreach ($candidate in $pythonCandidates) {
if (Test-Path $candidate) {
& $candidate main.py
exit $LASTEXITCODE
}
}
Write-Error "No usable Python launcher found. Install Python or Miniconda, or activate the sani environment first."