Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to download windows exe/msi and mac universal pkg if it doesn't exists for python version requested #276

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion builders/macos-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
38 changes: 32 additions & 6 deletions builders/win-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
}
}