blob: afd988e67e4cd787c58aeb786a7d8d3c7c89a6ad [file] [log] [blame]
Joshua Nelson775c3c02022-07-31 19:02:311#!/usr/bin/env pwsh
2
Josh Stonede8dedb2022-08-12 22:39:263# See ./x for why these scripts exist.
Joshua Nelson775c3c02022-07-31 19:02:314
ozkanonureea62022023-05-03 17:32:395$ErrorActionPreference = "Stop"
6
7# syntax check
jyn664ffa42023-06-24 18:16:398Get-Command -syntax ${PSCommandPath} >$null
ozkanonureea62022023-05-03 17:32:399
Joshua Nelson775c3c02022-07-31 19:02:3110$xpy = Join-Path $PSScriptRoot x.py
jyn2cf54e92023-12-09 14:43:2711$xpy_args = @($xpy) + $args
Joshua Nelson775c3c02022-07-31 19:02:3112
Albert Larsanc83ddae2022-10-13 08:20:3913function Get-Application($app) {
jynfa7e9652023-06-24 18:09:4814 $cmd = Get-Command $app -ErrorAction SilentlyContinue -CommandType Application | Select-Object -First 1
jynfa7e9652023-06-24 18:09:4815 return $cmd
Albert Larsanc83ddae2022-10-13 08:20:3916}
17
Chris Denton96501bd2022-12-28 19:41:4218function Invoke-Application($application, $arguments) {
jyn2cf54e92023-12-09 14:43:2719 & $application $arguments
20 Exit $LASTEXITCODE
Chris Denton96501bd2022-12-28 19:41:4221}
22
Joshua Nelson775c3c02022-07-31 19:02:3123foreach ($python in "py", "python3", "python", "python2") {
24 # NOTE: this only tests that the command exists in PATH, not that it's actually
25 # executable. The latter is not possible in a portable way, see
26 # https://github.com/PowerShell/PowerShell/issues/12625.
Albert Larsanc83ddae2022-10-13 08:20:3927 if (Get-Application $python) {
Joshua Nelson775c3c02022-07-31 19:02:3128 if ($python -eq "py") {
29 # Use python3, not python2
30 $xpy_args = @("-3") + $xpy_args
31 }
Chris Denton96501bd2022-12-28 19:41:4232 Invoke-Application $python $xpy_args
Joshua Nelson775c3c02022-07-31 19:02:3133 }
34}
35
Albert Larsanc83ddae2022-10-13 08:20:3936$found = (Get-Application "python*" | Where-Object {$_.name -match '^python[2-3]\.[0-9]+(\.exe)?$'})
37if (($null -ne $found) -and ($found.Length -ge 1)) {
38 $python = $found[0]
Chris Denton96501bd2022-12-28 19:41:4239 Invoke-Application $python $xpy_args
Albert Larsanc83ddae2022-10-13 08:20:3940}
41
jynfa7e9652023-06-24 18:09:4842$msg = "${PSCommandPath}: error: did not find python installed`n"
43$msg += "help: consider installing it from https://www.python.org/downloads/"
44Write-Error $msg -Category NotInstalled
Joshua Nelson775c3c02022-07-31 19:02:3145Exit 1