1+ Write-Host " Entering .appveyor/install.ps1"
2+ Write-Host " Build using $env: WINPYTHON "
13$pythonExe = " C:\$ ( $env: WINPYTHON ) \python.exe"
24
35# If the initial call to python --version fails, call "choco install %WINPYTHON%"
@@ -15,25 +17,83 @@ try {
1517
1618if (-not $pyVersionSucceeded ) {
1719 Write-Host " Python version check failed or Python not found at $pythonExe . Installing $env: WINPYTHON via Chocolatey..."
18- choco install -- allow- empty- checksums $env: WINPYTHON
20+ choco install -- force -- allow- empty- checksums $env: WINPYTHON
21+ dir C:\ProgramData\chocolatey\bin\python* .exe
22+ dir c:\python*
1923}
2024
21- # Set PYSITEDIR
22- $env: PYSITEDIR = & $pythonExe - c " import sys; print(sys.path[-1])"
23-
24- # Use mingw 32 bit until #3291 is resolved
2525# Add python and python user-base to path for pip installs
26- $extraPaths = @ (
27- " C:\$ ( $env: WINPYTHON ) " ,
28- " C:\$ ( $env: WINPYTHON ) \Scripts" ,
29- " C:\ProgramData\chocolatey\bin" ,
26+ $pythonPaths = @ ()
27+ if (Test-Path " C:\$ ( $env: WINPYTHON ) " ) {
28+ $pythonPaths += " C:\$ ( $env: WINPYTHON ) "
29+ }
30+
31+ # Always add chocolatey bin
32+ # Prioritize it if we just installed python there AND C:\PythonXX wasn't found
33+ if (-not $pyVersionSucceeded -and -not (Test-Path " C:\$ ( $env: WINPYTHON ) " )) {
34+ $pythonPaths = @ (" C:\ProgramData\chocolatey\bin" ) + $pythonPaths
35+ } else {
36+ $pythonPaths += " C:\ProgramData\chocolatey\bin"
37+ }
38+
39+ # Add tools AFTER python paths to avoid picking up MSYS/Cygwin python shims
40+ $toolPaths = @ (
3041 " C:\MinGW\bin" ,
3142 " C:\MinGW\msys\1.0\bin" ,
3243 " C:\cygwin\bin" ,
3344 " C:\msys64\usr\bin" ,
3445 " C:\msys64\mingw64\bin"
3546)
36- $env: PATH = ($extraPaths + @ ($env: PATH )) -join ' ;'
47+
48+ $env: PATH = ($pythonPaths + $toolPaths + @ ($env: PATH )) -join ' ;'
49+ # Ensure we have the correct path to the python executable,
50+ # explicitly avoiding MSYS/Cygwin versions.
51+ $pythonExe = $null
52+
53+ # Derive a version-specific shim name (e.g. Python310 -> python3.10.exe)
54+ $pyVersion = $env: WINPYTHON -replace " Python" , " " # e.g. "310"
55+ if ($pyVersion -match " ^(\d)(\d+)$" ) {
56+ $specName = " python$ ( $Matches [1 ]) .$ ( $Matches [2 ]) .exe" # e.g. "python3.10.exe"
57+ } else {
58+ $specName = " python.exe"
59+ }
60+
61+ $checkNames = @ (" $env: WINPYTHON .exe" , $specName , " python.exe" , " python3.exe" )
62+
63+ foreach ($name in $checkNames ) {
64+ Write-Host " Checking for Python shim: $name "
65+ $cmds = Get-Command $name - ErrorAction SilentlyContinue | Where-Object { $_.Path -notlike " *\msys64\*" -and $_.Path -notlike " *\cygwin\*" }
66+ if ($cmds ) {
67+ $pythonExe = ($cmds | Select-Object - First 1 ).Path
68+
69+ $pyDir = Split-Path - Parent $pythonExe
70+ $pyScripts = Join-Path $pyDir " Scripts"
71+ if (Test-Path $pyScripts ) {
72+ Write-Host " Adding $pyScripts to PATH"
73+ $env: PATH = " $pyScripts ;$env: PATH "
74+ }
75+
76+ & $pythonExe -- version
77+ break
78+ } else {
79+ Write-Host " Didn't find $name "
80+ }
81+ }
82+ if (-not $pythonExe -or -not (Test-Path $pythonExe )) {
83+ Write-Error " Could not find a valid Python executable (WINPYTHON=$env: WINPYTHON ). Aborting."
84+ exit 1
85+ }
86+
87+ Write-Host " Using Python at: $pythonExe "
88+
89+ Write-Host " PATH: $env: PATH "
90+
91+ # Set SCONS_PYTHON_BIN for future steps
92+ Set-AppveyorBuildVariable - Name " SCONS_PYTHON_BIN" - Value " $pythonExe "
93+
94+ # Set PYSITEDIR
95+ $env: PYSITEDIR = & $pythonExe - c " import sys; print(sys.path[-1])"
96+ Set-AppveyorBuildVariable - Name " PYSITEDIR" - Value " $env: PYSITEDIR "
3797
3898# pip installs
3999& $pythonExe - m pip install - U -- progress- bar off pip setuptools wheel
@@ -46,3 +106,4 @@ choco install --allow-empty-checksums dmd ldc swig vswhere xsltproc winflexbison
46106
47107# Show environment variables
48108Get-ChildItem Env: | Sort-Object Name
109+ Write-Host " Exiting .appveyor/install.ps1"
0 commit comments