@@ -8,6 +8,22 @@ $RequirementFiles = @("requirements.txt", "requirements-dev.txt", "requirements-
|
|||||||
$VenvName = ".venv"
|
$VenvName = ".venv"
|
||||||
$VenvDir = Join-Path $PSScriptRoot $VenvName
|
$VenvDir = Join-Path $PSScriptRoot $VenvName
|
||||||
|
|
||||||
|
# Supported Python minor versions (detection order: prefer newest first)
|
||||||
|
$SupportedMinorVersions = @(13,12,11)
|
||||||
|
# Build a human-readable supported versions string like "3.11, 3.12 and 3.13"
|
||||||
|
$asc = $SupportedMinorVersions | Sort-Object
|
||||||
|
if ($asc.Count -eq 1) {
|
||||||
|
$SupportedPythonVersions = "3.$($asc[0])"
|
||||||
|
}
|
||||||
|
elseif ($asc.Count -eq 2) {
|
||||||
|
$SupportedPythonVersions = "3.$($asc[0]) and 3.$($asc[1])"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$allButLast = ($asc[0..($asc.Count - 2)] | ForEach-Object { "3.$_" }) -join ", "
|
||||||
|
$last = "3.$($asc[-1])"
|
||||||
|
$SupportedPythonVersions = "$allButLast and $last"
|
||||||
|
}
|
||||||
|
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param (
|
param (
|
||||||
[string]$Message,
|
[string]$Message,
|
||||||
@@ -149,20 +165,21 @@ function Test-PythonExecutable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Find-PythonExecutable {
|
function Find-PythonExecutable {
|
||||||
$PythonExecutables = @(
|
# Build a list of candidate executables dynamically from supported versions
|
||||||
"python",
|
$PythonExecutables = @()
|
||||||
"python3.13",
|
$PythonExecutables += "python"
|
||||||
"python3.12",
|
foreach ($v in $SupportedMinorVersions) {
|
||||||
"python3.11",
|
$PythonExecutables += "python3.$v"
|
||||||
"python3",
|
}
|
||||||
"C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python313\python.exe",
|
$PythonExecutables += "python3"
|
||||||
"C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python312\python.exe",
|
|
||||||
"C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python311\python.exe",
|
|
||||||
"C:\Python313\python.exe",
|
|
||||||
"C:\Python312\python.exe",
|
|
||||||
"C:\Python311\python.exe"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
# Add common Windows installation paths for each supported minor version
|
||||||
|
foreach ($v in $SupportedMinorVersions) {
|
||||||
|
$PythonExecutables += "C:\\Users\\$env:USERNAME\\AppData\\Local\\Programs\\Python\\Python3$v\\python.exe"
|
||||||
|
}
|
||||||
|
foreach ($v in $SupportedMinorVersions) {
|
||||||
|
$PythonExecutables += "C:\\Python3$v\\python.exe"
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($Executable in $PythonExecutables) {
|
foreach ($Executable in $PythonExecutables) {
|
||||||
if (Test-PythonExecutable -PythonExecutable $Executable) {
|
if (Test-PythonExecutable -PythonExecutable $Executable) {
|
||||||
@@ -179,7 +196,7 @@ function Main {
|
|||||||
# Exit on lower versions than Python 3.11 or when Python executable not found
|
# Exit on lower versions than Python 3.11 or when Python executable not found
|
||||||
$PythonExecutable = Find-PythonExecutable
|
$PythonExecutable = Find-PythonExecutable
|
||||||
if ($null -eq $PythonExecutable) {
|
if ($null -eq $PythonExecutable) {
|
||||||
Write-Log "No suitable Python executable found. Please ensure that Python 3.11 or higher is installed and available in the system PATH." -Level 'ERROR'
|
Write-Log "No suitable Python executable found. Supported versions are: $SupportedPythonVersions. Please install one of these and ensure it's available in the system PATH." -Level 'ERROR'
|
||||||
Exit 1
|
Exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user