From 9314128cf79c6bc0d7011afbffc96dab0520dad8 Mon Sep 17 00:00:00 2001 From: Vijay Janapa Reddi Date: Thu, 5 Mar 2026 07:42:29 -0500 Subject: [PATCH] Fix Windows python3 availability in container build paths. Preserve container PATH during Windows docker-run steps and create/verify a python3 alias from Scoop Python so Quarto/Jupyter kernels that invoke python3 work reliably in both install-time and final verification checks. --- .github/workflows/book-build-baremetal.yml | 26 ++++++++++++++++++++++ .github/workflows/book-build-container.yml | 3 --- book/docker/windows/Dockerfile | 22 ++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/.github/workflows/book-build-baremetal.yml b/.github/workflows/book-build-baremetal.yml index c235a028e..0bc015756 100644 --- a/.github/workflows/book-build-baremetal.yml +++ b/.github/workflows/book-build-baremetal.yml @@ -513,6 +513,19 @@ jobs: } Write-Output "📊 Python version: $pythonVersion" + $pyExe = (python -c "import sys; print(sys.executable)").Trim() + $pyDir = Split-Path $pyExe -Parent + $py3Exe = Join-Path $pyDir "python3.exe" + if (-not (Test-Path $py3Exe)) { + Copy-Item $pyExe $py3Exe -Force + } + $python3Version = python3 --version + if ($LASTEXITCODE -ne 0) { + Write-Error "❌ python3 --version failed with exit code $LASTEXITCODE" + exit 1 + } + Write-Output "📊 Python3 version: $python3Version" + # Verify we got Python 3.13 if ($pythonVersion -notmatch "3\.13") { Write-Error "❌ Expected Python 3.13, got: $pythonVersion" @@ -1175,6 +1188,19 @@ jobs: Write-Output " $out" Write-Output "✅ Python verified" + - name: ✅ Verify Python3 (Windows) + if: matrix.enabled && runner.os == 'Windows' + shell: pwsh + run: | + $cmd = Get-Command python3 -ErrorAction SilentlyContinue + if (-not $cmd) { Write-Error "❌ Python3 not found"; exit 1 } + Write-Output "Resolved: $($cmd.Source)" + $out = & python3 --version 2>&1 | Select-Object -First 1 + $exitCode = if ($null -eq $LASTEXITCODE) { if ($?) { 0 } else { 1 } } else { [int]$LASTEXITCODE } + if ($exitCode -ne 0) { Write-Error "❌ Python3 check failed (exit $exitCode)"; exit 1 } + Write-Output " $out" + Write-Output "✅ Python3 verified" + - name: ✅ Verify R (Windows) if: matrix.enabled && runner.os == 'Windows' shell: pwsh diff --git a/.github/workflows/book-build-container.yml b/.github/workflows/book-build-container.yml index 4819bf587..c6ded5008 100644 --- a/.github/workflows/book-build-container.yml +++ b/.github/workflows/book-build-container.yml @@ -392,7 +392,6 @@ jobs: run: | Write-Host "🔨 Building ${{ matrix.format_name }} on Windows container..." docker run --rm -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto" ${{ env.CONTAINER_IMAGE }} pwsh -NoLogo -Command " - `$env:PATH = [Environment]::GetEnvironmentVariable('PATH','Machine') if (Test-Path '_quarto.yml') { Remove-Item '_quarto.yml' -Force } Copy-Item 'config\${{ matrix.config }}' '_quarto.yml' -Force quarto render --to ${{ matrix.render_target }} --output-dir '${{ matrix.output_dir }}' @@ -440,7 +439,6 @@ jobs: run: | Write-Host "🔨 Compressing PDF on Windows container..." docker run --rm -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} pwsh -NoLogo -Command " - `$env:PATH = [Environment]::GetEnvironmentVariable('PATH','Machine') if (Test-Path 'Machine-Learning-Systems.pdf') { Write-Host '📉 Compressing PDF with professional compression tool...' Write-Host '🔍 DEBUG: Current directory:' @@ -516,7 +514,6 @@ jobs: run: | Write-Host "🔨 Compressing EPUB on Windows container..." docker run --rm -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} pwsh -NoLogo -Command " - `$env:PATH = [Environment]::GetEnvironmentVariable('PATH','Machine') if (Test-Path 'Machine-Learning-Systems.epub') { Write-Host '📚 Compressing EPUB with optimized compression tool...' Write-Host '🔍 DEBUG: Current directory:' diff --git a/book/docker/windows/Dockerfile b/book/docker/windows/Dockerfile index 9c4e02b42..6bb880c1a 100644 --- a/book/docker/windows/Dockerfile +++ b/book/docker/windows/Dockerfile @@ -227,7 +227,19 @@ RUN Write-Host '=== STARTING PYTHON INSTALLATION ===' ; ` Write-Host "❌ Python install failed: version check exited $LASTEXITCODE" ; ` exit 1 ; ` } ; ` + $pyExe = (python -c "import sys; print(sys.executable)").Trim() ; ` + $pyDir = Split-Path $pyExe -Parent ; ` + $py3Exe = Join-Path $pyDir 'python3.exe' ; ` + if (-not (Test-Path $py3Exe)) { ` + Copy-Item $pyExe $py3Exe -Force ; ` + } ; ` + $pv3 = python3 --version ; ` + if ($LASTEXITCODE -ne 0) { ` + Write-Host "❌ Python install failed: python3 alias check exited $LASTEXITCODE" ; ` + exit 1 ; ` + } ; ` Write-Host "📦 Python installed: $pv" ; ` + Write-Host "📦 Python3 alias verified: $pv3" ; ` Write-Host '✅ Python installation complete' # ------------------------------------------------------------ @@ -382,6 +394,16 @@ RUN Write-Host '=== VERIFY: Python ===' ; ` Write-Host " $out" ; ` Write-Host '✅ Python verified' +RUN Write-Host '=== VERIFY: Python3 ===' ; ` + $cmd = Get-Command python3 -ErrorAction SilentlyContinue ; ` + if (-not $cmd) { Write-Host "❌ Python3 FAILED: command not found"; exit 1 } ; ` + Write-Host "Resolved: $($cmd.Source)" ; ` + $out = & python3 --version 2>&1 | Select-Object -First 1 ; ` + $exitCode = if ($null -eq $LASTEXITCODE) { if ($?) { 0 } else { 1 } } else { [int]$LASTEXITCODE } ; ` + if ($exitCode -ne 0) { Write-Host "❌ Python3 FAILED: exited $exitCode"; exit 1 } ; ` + Write-Host " $out" ; ` + Write-Host '✅ Python3 verified' + RUN Write-Host '=== VERIFY: R ===' ; ` $cmd = Get-Command Rscript -ErrorAction SilentlyContinue ; ` if (-not $cmd) { Write-Host "❌ R FAILED: command not found"; exit 1 } ; `