forked from cncf/gitdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitdm.ps1
More file actions
41 lines (37 loc) · 1.08 KB
/
gitdm.ps1
File metadata and controls
41 lines (37 loc) · 1.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
#!/usr/bin/env pwsh
param([Parameter(ValueFromRemainingArguments=$true)] [string[]]$Args)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$BaseDir = Join-Path $ScriptDir 'src'
$Engine = Join-Path $BaseDir 'cncfdm.py'
function Pick-Python {
if ($env:GITDM_PY) { return $env:GITDM_PY }
foreach ($cand in @('py -2','python2','pypy','pypy2')) {
try {
if ($cand -eq 'py -2') {
& py -2 - <<'PY'
import sys
print(2 if sys.version_info[0]==2 else 3)
PY
if ($LASTEXITCODE -eq 0) { return 'py -2' }
} else {
if (Get-Command ($cand.Split(' ')[0]) -ErrorAction SilentlyContinue) { return $cand }
}
} catch { }
}
if (Get-Command python -ErrorAction SilentlyContinue) {
$ver = & python - <<'PY'
import sys
print(sys.version_info[0])
PY
if ($ver -eq 2) { return 'python' }
}
return $null
}
$py = Pick-Python
if (-not $py) {
Write-Error 'gitdm requires Python 2 or PyPy. Install python2/pypy or set GITDM_PY.'
exit 1
}
# Pass through stdin/stdout; add -b to point at src/
& $py $Engine -b "$BaseDir/" @Args
exit $LASTEXITCODE