From 1fc813fd6ab04402b9dc97f46530a88e15295e32 Mon Sep 17 00:00:00 2001 From: Adrian Vladu Date: Wed, 6 May 2026 15:46:54 +0300 Subject: [PATCH] python: add pymanager Python download option Signed-off-by: Adrian Vladu --- .github/workflows/build_test_cbsinit.yml | 6 ++- BuildAutomation/BuildCloudbaseInitSetup.ps1 | 17 +++++--- BuildAutomation/BuildUtils.ps1 | 48 +++++++++++++++++++++ 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_test_cbsinit.yml b/.github/workflows/build_test_cbsinit.yml index 2cfa3ddd..88258c05 100644 --- a/.github/workflows/build_test_cbsinit.yml +++ b/.github/workflows/build_test_cbsinit.yml @@ -11,6 +11,7 @@ jobs: os: ['windows-2022'] download_official_python_msi: ["true"] remove_python_pycs: ["true"] + install_with_pymanager: ["true"] cbsinit_repo: ['https://github.com/cloudbase/cloudbase-init'] cbsinit_branch: ['master'] python_version: ['3.14_4'] @@ -34,10 +35,11 @@ jobs: -CloudbaseInitRepoBranch ${{ matrix.cbsinit_branch }} ^ -InstallOfficialPythonMsi:$${{ matrix.download_official_python_msi }} ^ -OfficialPythonMsiChecksum "C10234D0D9BD89F6F6DD55BAE28EDE0F97EE0DF4" ^ - -RemovePythonPycs:$${{ matrix.remove_python_pycs }} + -RemovePythonPycs:$${{ matrix.remove_python_pycs }} ^ + -InstallOfficialPythonUsingPyManager:$${{ matrix.install_with_pymanager }} - uses: actions/upload-artifact@v7 with: - name: "CloudbaseInit_platform-${{ matrix.platform }}_build-env-os-${{ matrix.os }}_download-official-msi-${{ matrix.download_official_python_msi }}_remove-pycs-${{ matrix.remove_python_pycs }}_cbs-init-branch-${{ matrix.cbsinit_branch }}_MSI" + name: "CloudbaseInit_platform-${{ matrix.platform }}_build-env-os-${{ matrix.os }}_download-official-msi-${{ matrix.download_official_python_msi }}_remove-pycs-${{ matrix.remove_python_pycs }}_install-with-pymanager${{ matrix.install_with_pymanager }}_cbs-init-branch-${{ matrix.cbsinit_branch }}_MSI" path: 'CloudbaseInitSetup/bin/release/${{ matrix.platform }}/CloudbaseInitSetup.msi' - name: Download external dependencies shell: powershell diff --git a/BuildAutomation/BuildCloudbaseInitSetup.ps1 b/BuildAutomation/BuildCloudbaseInitSetup.ps1 index 1ad9a7c1..a69d9a34 100644 --- a/BuildAutomation/BuildCloudbaseInitSetup.ps1 +++ b/BuildAutomation/BuildCloudbaseInitSetup.ps1 @@ -13,7 +13,8 @@ Param( [string]$VCVars = "2019", [switch]$InstallOfficialPythonMsi = $false, [string]$OfficialPythonMsiChecksum = "C10234D0D9BD89F6F6DD55BAE28EDE0F97EE0DF4", - [switch]$RemovePythonPycs = $false + [switch]$RemovePythonPycs = $false, + [switch]$InstallOfficialPythonUsingPyManager = $false ) $ErrorActionPreference = "Stop" @@ -80,12 +81,18 @@ try $python_template_dir = join-path $cloudbaseInitInstallerDir "Python$($pythonversion.replace('.', ''))_${platform}_Template" + # TODO(avladu): stick to just only one way to download Python, preferably the pymanager once it gets ironed out if ($InstallOfficialPythonMsi) { - if (!$OfficialPythonMsiChecksum) { - throw "Please set a OfficialPythonMsiChecksum parameter value." + if ($InstallOfficialPythonUsingPyManager) { + Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue + DownloadInstall-PythonUsingPyManager $platform $python_template_dir $pythonversion + } else { + if (!$OfficialPythonMsiChecksum) { + throw "Please set a OfficialPythonMsiChecksum parameter value." + } + Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue + DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $OfficialPythonMsiChecksum } - Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue - DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $OfficialPythonMsiChecksum } CheckCopyDir $python_template_dir $python_dir diff --git a/BuildAutomation/BuildUtils.ps1 b/BuildAutomation/BuildUtils.ps1 index 604f52e2..a9c3f13e 100644 --- a/BuildAutomation/BuildUtils.ps1 +++ b/BuildAutomation/BuildUtils.ps1 @@ -460,3 +460,51 @@ function DownloadInstall-PythonMsi($platform, $python_template_dir, $pythonVersi } } + +function DownloadInstall-PythonUsingPyManager($platform, $python_template_dir, $pythonVersion) { + $pythonManagerUrl = "https://www.python.org/ftp/python/pymanager/python-manager-26.1.msix" + $pythonManagerPath = Join-Path (Resolve-Path "${python_template_dir}/..").Path "/python-manager.exe" + + $pythonManagerPackage = Get-AppPackage -Name PythonSoftwareFoundation.PythonManager -ErrorAction SilentlyContinue + + if (!$pythonManagerPackage) { + ExecRetry { DownloadFile $pythonManagerUrl $pythonManagerPath } + Add-AppPackage -Path $pythonManagerPath + } + + $platformSuffix = "" + if ($platform -eq "x86") { + $platformSuffix = "-32" + } + if ($platform -eq "arm64") { + $platformSuffix = "-arm64" + } + + if (Test-Path $python_template_dir) { + throw "$python_template_dir folder already exists" + } + + $pythonVersionEscaped = $pythonVersion.replace("_",".") + $platformSuffix + pymanager.exe install --target=$python_template_dir --force --update $pythonVersionEscaped + if ($LASTEXITCODE) { + throw "Failed to install python in directory: ${python_template_dir}" + } + + if (!(Test-Path $python_template_dir)) { + throw "$python_template_dir has not been created" + } + + & "$python_template_dir/python.exe" --version + if ($LASTEXITCODE) { + throw "Failed to run python in directory: ${python_template_dir}" + } + + Remove-Item -Force -Recurse "$python_template_dir/DLLs/_tkinter.pyd" + Remove-Item -Force -Recurse "$python_template_dir/DLLs/tcl*.dll" + Remove-Item -Force -Recurse "$python_template_dir/DLLs/tk*.dll" + Remove-Item -Force -Recurse "$python_template_dir/Doc" + Remove-Item -Force -Recurse "$python_template_dir/Lib/tkinter" + Remove-Item -Force -Recurse "$python_template_dir/Lib/turtle.py" + Remove-Item -Force -Recurse "$python_template_dir/Lib/turtledemo" + Remove-Item -Force -Recurse "$python_template_dir/tcl" +} \ No newline at end of file