Skip to content

Commit 97745c7

Browse files
committed
python: add pymanager Python download option
Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
1 parent d5226dc commit 97745c7

3 files changed

Lines changed: 51 additions & 7 deletions

File tree

.github/workflows/build_test_cbsinit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
max-parallel: 100
1010
matrix:
1111
os: ['windows-2022']
12-
download_official_python_msi: ["true", "false"]
12+
download_official_python_msi: ["true"]
1313
cbsinit_repo: ['https://github.com/cloudbase/cloudbase-init']
1414
cbsinit_branch: ['master']
1515
python_version: ['3.14_4']
@@ -32,7 +32,7 @@ jobs:
3232
-CloudbaseInitRepoUrl ${{ matrix.cbsinit_repo }} ^
3333
-CloudbaseInitRepoBranch ${{ matrix.cbsinit_branch }} ^
3434
-InstallOfficialPythonMsi:$${{ matrix.download_official_python_msi }} ^
35-
-OfficialPythonMsiChecksum "C10234D0D9BD89F6F6DD55BAE28EDE0F97EE0DF4"
35+
-InstallOfficialPythonUsingPyManager:$true
3636
- uses: actions/upload-artifact@v7
3737
with:
3838
name: "CloudbaseInit_${{ matrix.platform }}_${{ matrix.os }}_MSI_${{ matrix.cbsinit_branch }}"

BuildAutomation/BuildCloudbaseInitSetup.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Param(
1212
[string]$SignTimestampUrl = "http://timestamp.digicert.com?alg=sha256",
1313
[string]$VCVars = "2019",
1414
[switch]$InstallOfficialPythonMsi = $false,
15-
[string]$OfficialPythonMsiChecksum = "C10234D0D9BD89F6F6DD55BAE28EDE0F97EE0DF4"
15+
[string]$OfficialPythonMsiChecksum = "C10234D0D9BD89F6F6DD55BAE28EDE0F97EE0DF4",
16+
[switch]$InstallOfficialPythonUsingPyManager = $false
1617
)
1718

1819
$ErrorActionPreference = "Stop"
@@ -80,11 +81,16 @@ try
8081
$python_template_dir = join-path $cloudbaseInitInstallerDir "Python$($pythonversion.replace('.', ''))_${platform}_Template"
8182

8283
if ($InstallOfficialPythonMsi) {
83-
if (!$OfficialPythonMsiChecksum) {
84-
throw "Please set a OfficialPythonMsiChecksum parameter value."
84+
if ($InstallOfficialPythonUsingPyManager) {
85+
Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue
86+
DownloadInstall-PythonUsingPyManager $platform $python_template_dir $pythonversion
87+
} else {
88+
if (!$OfficialPythonMsiChecksum) {
89+
throw "Please set a OfficialPythonMsiChecksum parameter value."
90+
}
91+
Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue
92+
DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $OfficialPythonMsiChecksum
8593
}
86-
Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue
87-
DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $OfficialPythonMsiChecksum
8894
}
8995

9096
CheckCopyDir $python_template_dir $python_dir

BuildAutomation/BuildUtils.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,41 @@ function DownloadInstall-PythonMsi($platform, $python_template_dir, $pythonVersi
460460
}
461461

462462
}
463+
464+
function DownloadInstall-PythonUsingPyManager($platform, $python_template_dir, $pythonVersion) {
465+
$pythonManagerUrl = "https://www.python.org/ftp/python/pymanager/python-manager-26.1.msix"
466+
$pythonManagerPath = Join-Path (Resolve-Path "${python_template_dir}/..").Path "/python-manager.exe"
467+
468+
$pythonManagerPackage = Get-AppPackage -Name PythonSoftwareFoundation.PythonManager -ErrorAction SilentlyContinue
469+
470+
if (!$pythonManagerPackage) {
471+
ExecRetry { DownloadFile $pythonManagerUrl $pythonManagerPath }
472+
Add-AppPackage -Path $pythonManagerPath
473+
}
474+
475+
$platformSuffix = ""
476+
if ($platform -eq "x86") {
477+
$platformSuffix = "-32"
478+
}
479+
if ($platform -eq "arm64") {
480+
$platformSuffix = "-arm64"
481+
}
482+
483+
if (Test-Path $python_template_dir) {
484+
throw "$python_template_dir folder already exists"
485+
}
486+
487+
$pythonVersionEscaped = $pythonVersion.replace("_",".") + $platformSuffix
488+
pymanager.exe install --target=$python_template_dir --force --update $pythonVersionEscaped
489+
if ($LASTEXITCODE) {
490+
throw "Failed to install python in directory: ${python_template_dir}"
491+
}
492+
& "$python_template_dir/python.exe" --version
493+
if ($LASTEXITCODE) {
494+
throw "Failed to run python in directory: ${python_template_dir}"
495+
}
496+
if (!(Test-Path $python_template_dir)) {
497+
throw "$python_template_dir has not been created"
498+
}
499+
500+
}

0 commit comments

Comments
 (0)