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() 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" + } } }