Skip to content

Commit cead467

Browse files
authored
Update win-setup-template.ps1
1 parent 3023b15 commit cead467

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

installers/win-setup-template.ps1

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[String] $Architecture = "{{__ARCHITECTURE__}}"
2+
[String] $HardwareArchitecture = "{{__HARDWARE_ARCHITECTURE__}}"
23
[String] $Version = "{{__VERSION__}}"
34
[String] $PythonExecName = "{{__PYTHON_EXEC_NAME__}}"
45

@@ -25,7 +26,7 @@ function Remove-RegistryEntries {
2526
[Parameter(Mandatory)][Int32] $MinorVersion
2627
)
2728

28-
$versionFilter = Get-RegistryVersionFilter -Architecture $Architecture -MajorVersion $MajorVersion -MinorVersion $MinorVersion
29+
$versionFilter = Get-RegistryVersionFilter -Architecture $HardwareArchitecture -MajorVersion $MajorVersion -MinorVersion $MinorVersion
2930

3031
$regPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
3132
if (Test-Path -Path Registry::$regPath) {
@@ -61,13 +62,15 @@ function Remove-RegistryEntries {
6162
function Get-ExecParams {
6263
param(
6364
[Parameter(Mandatory)][Boolean] $IsMSI,
65+
[Parameter(Mandatory)][Boolean] $IsFreeThreaded,
6466
[Parameter(Mandatory)][String] $PythonArchPath
6567
)
6668

6769
if ($IsMSI) {
6870
"TARGETDIR=$PythonArchPath ALLUSERS=1"
6971
} else {
70-
"DefaultAllUsersTargetDir=$PythonArchPath InstallAllUsers=1"
72+
$Include_freethreaded = if ($IsFreeThreaded) { "Include_freethreaded=1" } else { "" }
73+
"DefaultAllUsersTargetDir=$PythonArchPath InstallAllUsers=1 $Include_freethreaded"
7174
}
7275
}
7376

@@ -81,6 +84,7 @@ $PythonVersionPath = Join-Path -Path $PythonToolcachePath -ChildPath $Version
8184
$PythonArchPath = Join-Path -Path $PythonVersionPath -ChildPath $Architecture
8285

8386
$IsMSI = $PythonExecName -match "msi"
87+
$IsFreeThreaded = $Architecture -match "-freethreaded"
8488

8589
$MajorVersion = $Version.Split('.')[0]
8690
$MinorVersion = $Version.Split('.')[1]
@@ -120,13 +124,24 @@ Write-Host "Copy Python binaries to $PythonArchPath"
120124
Copy-Item -Path ./$PythonExecName -Destination $PythonArchPath | Out-Null
121125

122126
Write-Host "Install Python $Version in $PythonToolcachePath..."
123-
$ExecParams = Get-ExecParams -IsMSI $IsMSI -PythonArchPath $PythonArchPath
127+
$ExecParams = Get-ExecParams -IsMSI $IsMSI -IsFreeThreaded $IsFreeThreaded -PythonArchPath $PythonArchPath
124128

125129
cmd.exe /c "cd $PythonArchPath && call $PythonExecName $ExecParams /quiet"
126130
if ($LASTEXITCODE -ne 0) {
127131
Throw "Error happened during Python installation"
128132
}
129133

134+
# print out all files in $PythonArchPath
135+
Write-Host "Files in $PythonArchPath"
136+
$files = Get-ChildItem -Path $PythonArchPath -File -Recurse
137+
Write-Output $files
138+
139+
if ($IsFreeThreaded) {
140+
# Delete python.exe and create a symlink to free-threaded exe
141+
Remove-Item -Path "$PythonArchPath\python.exe" -Force
142+
New-Item -Path "$PythonArchPath\python.exe" -ItemType SymbolicLink -Value "$PythonArchPath\python${MajorVersion}.${MinorVersion}t.exe"
143+
}
144+
130145
Write-Host "Create `python3` symlink"
131146
if ($MajorVersion -ne "2") {
132147
New-Item -Path "$PythonArchPath\python3.exe" -ItemType SymbolicLink -Value "$PythonArchPath\python.exe"

0 commit comments

Comments
 (0)