From 8f472790642f0b0a7446e80aad820cb93c0a58cf Mon Sep 17 00:00:00 2001 From: Norio Tamaru Date: Mon, 25 May 2026 14:58:32 +0900 Subject: [PATCH] Add Python fallback to dev check --- scripts/dev_check.ps1 | 122 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) diff --git a/scripts/dev_check.ps1 b/scripts/dev_check.ps1 index f4bd662..65db94c 100644 --- a/scripts/dev_check.ps1 +++ b/scripts/dev_check.ps1 @@ -29,14 +29,132 @@ function Invoke-Check { } } +function Invoke-PytestCandidate { + param( + [Parameter(Mandatory = $true)] + [string]$Label, + + [Parameter(Mandatory = $true)] + [string]$Executable, + + [Parameter(Mandatory = $true)] + [string[]]$Arguments, + + [bool]$RequireFile = $false + ) + + $commandText = "$Executable $($Arguments -join ' ')" + Write-Host "" + Write-Host "Trying: $Label" + Write-Host $commandText + + if ($RequireFile -and -not (Test-Path -LiteralPath $Executable)) { + return @{ + Started = $false + Success = $false + Reason = "executable not found" + } + } + + try { + $global:LASTEXITCODE = 0 + $output = & $Executable @Arguments 2>&1 + $exitCode = $LASTEXITCODE + if ($output) { + $output | ForEach-Object { Write-Host $_ } + } + + $outputText = ($output | Out-String) + if ($exitCode -ne 0 -and $outputText -match "No module named pytest") { + return @{ + Started = $false + Success = $false + Reason = "pytest module not found" + } + } + + if ($exitCode -eq 0) { + return @{ + Started = $true + Success = $true + Reason = "pytest completed successfully" + } + } + + return @{ + Started = $true + Success = $false + Reason = "pytest failed with exit code $exitCode" + } + } + catch { + return @{ + Started = $false + Success = $false + Reason = $_.Exception.Message + } + } +} + +function Invoke-Pytest { + $codexPython = "C:\Users\tamaru\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe" + $basetemp = Join-Path $env:TEMP "utr_lan_pytest_tmp" + $attempts = @() + $candidates = @( + @{ + Label = "py -m pytest tests" + Executable = "py" + Arguments = @("-m", "pytest", "tests") + RequireFile = $false + }, + @{ + Label = "python -m pytest tests" + Executable = "python" + Arguments = @("-m", "pytest", "tests") + RequireFile = $false + }, + @{ + Label = "Codex bundled Python" + Executable = $codexPython + Arguments = @("-m", "pytest", "tests", "-p", "no:cacheprovider", "--basetemp", $basetemp) + RequireFile = $true + } + ) + + foreach ($candidate in $candidates) { + $label = $candidate["Label"] + $executable = $candidate["Executable"] + $arguments = $candidate["Arguments"] + $requireFile = $candidate["RequireFile"] + $result = Invoke-PytestCandidate -Label $label -Executable $executable -Arguments $arguments -RequireFile $requireFile + + $attempts += ("- {0}: {1}" -f $label, $result["Reason"]) + + if ($result["Started"] -and $result["Success"]) { + $global:LASTEXITCODE = 0 + return + } + + if ($result["Started"] -and -not $result["Success"]) { + throw $result["Reason"] + } + } + + $notExecutedText = "pytest" + [string][char]0x672A + [string][char]0x5B9F + [string][char]0x884C + Write-Host $notExecutedText -ForegroundColor Red + Write-Host "Tried:" + $attempts | ForEach-Object { Write-Host $_ } + throw "pytest was not executed" +} + Push-Location $repoRoot try { Invoke-Check "git status --short" { git status --short } - Invoke-Check "py -m pytest tests" { - py -m pytest tests + Invoke-Check "pytest" { + Invoke-Pytest } $scanScript = Join-Path $PSScriptRoot ("sec" + "ret_scan.ps1")