Skip to content

Commit 798df5e

Browse files
authored
Merge pull request #61 from ader1990/add_pymanager_support
python: add pymanager Python download option
2 parents e6b7470 + 1fc813f commit 798df5e

3 files changed

Lines changed: 64 additions & 7 deletions

File tree

.github/workflows/build_test_cbsinit.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
os: ['windows-2022']
1212
download_official_python_msi: ["true"]
1313
remove_python_pycs: ["true"]
14+
install_with_pymanager: ["true"]
1415
cbsinit_repo: ['https://github.com/cloudbase/cloudbase-init']
1516
cbsinit_branch: ['master']
1617
python_version: ['3.14_4']
@@ -34,10 +35,11 @@ jobs:
3435
-CloudbaseInitRepoBranch ${{ matrix.cbsinit_branch }} ^
3536
-InstallOfficialPythonMsi:$${{ matrix.download_official_python_msi }} ^
3637
-OfficialPythonMsiChecksum "C10234D0D9BD89F6F6DD55BAE28EDE0F97EE0DF4" ^
37-
-RemovePythonPycs:$${{ matrix.remove_python_pycs }}
38+
-RemovePythonPycs:$${{ matrix.remove_python_pycs }} ^
39+
-InstallOfficialPythonUsingPyManager:$${{ matrix.install_with_pymanager }}
3840
- uses: actions/upload-artifact@v7
3941
with:
40-
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"
42+
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"
4143
path: 'CloudbaseInitSetup/bin/release/${{ matrix.platform }}/CloudbaseInitSetup.msi'
4244
- name: Download external dependencies
4345
shell: powershell

BuildAutomation/BuildCloudbaseInitSetup.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Param(
1313
[string]$VCVars = "2019",
1414
[switch]$InstallOfficialPythonMsi = $false,
1515
[string]$OfficialPythonMsiChecksum = "C10234D0D9BD89F6F6DD55BAE28EDE0F97EE0DF4",
16-
[switch]$RemovePythonPycs = $false
16+
[switch]$RemovePythonPycs = $false,
17+
[switch]$InstallOfficialPythonUsingPyManager = $false
1718
)
1819

1920
$ErrorActionPreference = "Stop"
@@ -80,12 +81,18 @@ try
8081

8182
$python_template_dir = join-path $cloudbaseInitInstallerDir "Python$($pythonversion.replace('.', ''))_${platform}_Template"
8283

84+
# TODO(avladu): stick to just only one way to download Python, preferably the pymanager once it gets ironed out
8385
if ($InstallOfficialPythonMsi) {
84-
if (!$OfficialPythonMsiChecksum) {
85-
throw "Please set a OfficialPythonMsiChecksum parameter value."
86+
if ($InstallOfficialPythonUsingPyManager) {
87+
Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue
88+
DownloadInstall-PythonUsingPyManager $platform $python_template_dir $pythonversion
89+
} else {
90+
if (!$OfficialPythonMsiChecksum) {
91+
throw "Please set a OfficialPythonMsiChecksum parameter value."
92+
}
93+
Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue
94+
DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $OfficialPythonMsiChecksum
8695
}
87-
Remove-Item -Recurse -Force $python_template_dir -ErrorAction SilentlyContinue
88-
DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $OfficialPythonMsiChecksum
8996
}
9097

9198
CheckCopyDir $python_template_dir $python_dir

BuildAutomation/BuildUtils.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,51 @@ 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+
493+
if (!(Test-Path $python_template_dir)) {
494+
throw "$python_template_dir has not been created"
495+
}
496+
497+
& "$python_template_dir/python.exe" --version
498+
if ($LASTEXITCODE) {
499+
throw "Failed to run python in directory: ${python_template_dir}"
500+
}
501+
502+
Remove-Item -Force -Recurse "$python_template_dir/DLLs/_tkinter.pyd"
503+
Remove-Item -Force -Recurse "$python_template_dir/DLLs/tcl*.dll"
504+
Remove-Item -Force -Recurse "$python_template_dir/DLLs/tk*.dll"
505+
Remove-Item -Force -Recurse "$python_template_dir/Doc"
506+
Remove-Item -Force -Recurse "$python_template_dir/Lib/tkinter"
507+
Remove-Item -Force -Recurse "$python_template_dir/Lib/turtle.py"
508+
Remove-Item -Force -Recurse "$python_template_dir/Lib/turtledemo"
509+
Remove-Item -Force -Recurse "$python_template_dir/tcl"
510+
}

0 commit comments

Comments
 (0)