-
Notifications
You must be signed in to change notification settings - Fork 823
Expand file tree
/
Copy pathgitdm.ps1
More file actions
58 lines (50 loc) · 1.58 KB
/
gitdm.ps1
File metadata and controls
58 lines (50 loc) · 1.58 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
#!/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 Test-Python2 {
param(
[Parameter(Mandatory=$true)] [string]$Exe,
[string[]]$ExeArgs = @()
)
try {
& $Exe @ExeArgs -c "import sys; sys.exit(0 if sys.version_info[0] == 2 else 1)" *> $null
return ($LASTEXITCODE -eq 0)
} catch {
return $false
}
}
function Pick-Python {
# Allow override via environment variable.
if ($env:GITDM_PY) {
return [pscustomobject]@{ Exe = $env:GITDM_PY; Args = @() }
}
# Prefer Python Launcher (if Python 2 is installed).
if (Get-Command py -ErrorAction SilentlyContinue) {
if (Test-Python2 -Exe 'py' -ExeArgs @('-2')) {
return [pscustomobject]@{ Exe = 'py'; Args = @('-2') }
}
}
# Prefer explicit Python 2 binaries, then fall back to python only if it is v2.
foreach ($cand in @('python2', 'pypy2', 'pypy', 'python')) {
if (Get-Command $cand -ErrorAction SilentlyContinue) {
if (Test-Python2 -Exe $cand) {
return [pscustomobject]@{ Exe = $cand; Args = @() }
}
}
}
return $null
}
$py = Pick-Python
if (-not $py) {
Write-Error 'gitdm requires Python 2 or PyPy. Install python2/pypy2 or set GITDM_PY.'
exit 1
}
# Pass through stdin/stdout; add -b to point at src/
if ($MyInvocation.ExpectingInput) {
$input | & $py.Exe @($py.Args) $Engine -b "$BaseDir/" @Args
} else {
& $py.Exe @($py.Args) $Engine -b "$BaseDir/" @Args
}
exit $LASTEXITCODE