@@ -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