40 lines
1.1 KiB
PowerShell
40 lines
1.1 KiB
PowerShell
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function Resolve-SdtPython {
|
|
$candidates = @('python')
|
|
if ($IsWindows) { $candidates += 'py' } else { $candidates += 'python3' }
|
|
foreach ($c in $candidates) {
|
|
try {
|
|
& $c --version *> $null
|
|
if ($LASTEXITCODE -eq 0) { return $c }
|
|
} catch {}
|
|
}
|
|
return 'python'
|
|
}
|
|
|
|
function Resolve-SdtScriptPath {
|
|
param([Parameter(Mandatory=$true)][string]$ScriptName)
|
|
|
|
$bundled = Join-Path $PSScriptRoot $ScriptName
|
|
if (Test-Path $bundled) { return $bundled }
|
|
|
|
$project = Join-Path (Join-Path $PSScriptRoot '..') ('scripts\\' + $ScriptName)
|
|
if (Test-Path $project) { return (Resolve-Path $project).Path }
|
|
|
|
throw "Python helper script not found: $ScriptName"
|
|
}
|
|
|
|
function Invoke-SdtPythonScript {
|
|
param(
|
|
[Parameter(Mandatory=$true)][string]$ScriptName,
|
|
[string[]]$ForwardArgs = @()
|
|
)
|
|
|
|
$python = Resolve-SdtPython
|
|
$scriptPath = Resolve-SdtScriptPath -ScriptName $ScriptName
|
|
|
|
& $python $scriptPath @ForwardArgs
|
|
exit $LASTEXITCODE
|
|
}
|