SDT/scripts/_pwsh-python-shim.ps1
2026-03-01 20:52:56 -06:00

48 lines
1.3 KiB
PowerShell

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Test-SdtIsWindows {
if (Get-Variable -Name IsWindows -Scope Global -ErrorAction SilentlyContinue) {
return [bool]$global:IsWindows
}
return $env:OS -eq 'Windows_NT'
}
function Resolve-SdtPython {
$candidates = @('python')
if (Test-SdtIsWindows) { $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
}