From 8a0efa35fdb4df9849de23def40118cb2387577b Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Wed, 29 May 2024 07:28:18 +0200 Subject: [PATCH 1/2] Don't try to continue for windows if download link for exe/msi doesn't exists for python verrsion requested --- builders/win-python-builder.psm1 | 38 +++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/builders/win-python-builder.psm1 b/builders/win-python-builder.psm1 index cdaa0494..7ecc715d 100644 --- a/builders/win-python-builder.psm1 +++ b/builders/win-python-builder.psm1 @@ -82,6 +82,28 @@ class WinPythonBuilder : PythonBuilder { return $uri } + [bool] PkgExists() { + <# + .SYNOPSIS + Checks if the Universal Pkg Uri actually exists. + #> + $pkgUri = $this.GetSourceUri() + + try { + $statusCode = (Invoke-WebRequest -Uri $pkgUri -UseBasicParsing -DisableKeepAlive -Method head).StatusCode + if ($statusCode -eq 200) { + return $true + } else { + Write-Host "File at $pkgUri did not appear to be valid, with status code '$statusCode'" + return $false; + } + } catch { + $statusCode = [int]$_.Exception.Response.StatusCode + Write-Host "File at $pkgUri did not appear to be valid, with status code '$statusCode'" + return $false + } + } + [string] Download() { <# .SYNOPSIS @@ -131,13 +153,17 @@ class WinPythonBuilder : PythonBuilder { Generates Python artifact from downloaded Python installation executable. #> - Write-Host "Download Python $($this.Version) [$($this.Architecture)] executable..." - $this.Download() + if ($this.PkgExists()) { + Write-Host "Download Python $($this.Version) [$($this.Architecture)] executable..." + $this.Download() - Write-Host "Create installation script..." - $this.CreateInstallationScript() + Write-Host "Create installation script..." + $this.CreateInstallationScript() - Write-Host "Archive artifact" - $this.ArchiveArtifact() + Write-Host "Archive artifact" + $this.ArchiveArtifact() + } else { + Write-Host "No source URI can be found" + } } } From 16b5b71cc91eea69250248f34c41c4f1677bc3d9 Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Wed, 29 May 2024 07:50:25 +0200 Subject: [PATCH 2/2] Do Not try to download a universal mac pkg if there is none --- builders/macos-python-builder.psm1 | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/builders/macos-python-builder.psm1 b/builders/macos-python-builder.psm1 index 6b36fddc..c244da61 100644 --- a/builders/macos-python-builder.psm1 +++ b/builders/macos-python-builder.psm1 @@ -151,6 +151,28 @@ class macOSPythonBuilder : NixPythonBuilder { return $pkgLocation } + [bool] PkgExists() { + <# + .SYNOPSIS + Checks if the Universal Pkg Uri actually exists. + #> + $pkgUri = $this.GetPkgUri() + + try { + $statusCode = (Invoke-WebRequest -Uri $pkgUri -UseBasicParsing -DisableKeepAlive -Method head).StatusCode + if ($statusCode -eq 200) { + return $true + } else { + Write-Host "File at $pkgUri did not appear to be valid, with status code '$statusCode'" + return $false; + } + } catch { + $statusCode = [int]$_.Exception.Response.StatusCode + Write-Host "File at $pkgUri did not appear to be valid, with status code '$statusCode'" + return $false + } + } + [void] CreateInstallationScriptPkg() { <# .SYNOPSIS @@ -180,7 +202,7 @@ class macOSPythonBuilder : NixPythonBuilder { $PkgVersion = [semver]"3.11.0-beta.1" - if (($this.Version -ge $PkgVersion) -or ($this.Architecture -eq "arm64")) { + if ((($this.Version -ge $PkgVersion) -or ($this.Architecture -eq "arm64")) -and ($this.PkgExists())) { Write-Host "Download Python $($this.Version) [$($this.Architecture)] package..." $this.DownloadPkg()