Add support for PYTHON_BUILD_MIRROR_URL when checksums do not exist (#1673)

This commit is contained in:
James Curtin 2020-10-03 14:30:46 -04:00 committed by GitHub
parent c9eab47752
commit 5d84eed869
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View file

@ -109,6 +109,8 @@ You can set certain environment variables to control the build process.
downloaded package files. downloaded package files.
* `PYTHON_BUILD_MIRROR_URL` overrides the default mirror URL root to one of your * `PYTHON_BUILD_MIRROR_URL` overrides the default mirror URL root to one of your
choosing. choosing.
* `PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM`, if set, does not append the SHA2
checksum of the file to the mirror URL.
* `PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download packages from * `PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download packages from
their original source URLs instead of using a mirror. their original source URLs instead of using a mirror.
* `PYTHON_BUILD_ROOT` overrides the default location from where build definitions * `PYTHON_BUILD_ROOT` overrides the default location from where build definitions
@ -182,6 +184,10 @@ You can point python-build to another mirror by specifying the
own local mirror, for example. Package mirror URLs are constructed by joining own local mirror, for example. Package mirror URLs are constructed by joining
this variable with the SHA2 checksum of the package file. this variable with the SHA2 checksum of the package file.
If the mirror being used does not have the same checksum (*e.g.* with a
pull-through cache like Artifactory), you can set the
`PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM` environment variable.
If you don't have an SHA2 program installed, python-build will skip the download If you don't have an SHA2 program installed, python-build will skip the download
mirror and use official URLs instead. You can force python-build to bypass the mirror and use official URLs instead. You can force python-build to bypass the
mirror by setting the `PYTHON_BUILD_SKIP_MIRROR` environment variable. mirror by setting the `PYTHON_BUILD_SKIP_MIRROR` environment variable.

View file

@ -480,7 +480,12 @@ reuse_existing_tarball() {
} }
download_tarball() { download_tarball() {
local package_url="$1" local official_source="www.python.org/ftp/python"
if [ -n "$PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM" ]; then
local package_url="$(echo "$1" | sed -e "s|.*//${URL_BASE:-$official_source}|$PYTHON_BUILD_MIRROR_URL|g")"
else
local package_url="$1"
fi
[ -n "$package_url" ] || return 1 [ -n "$package_url" ] || return 1
local package_filename="$2" local package_filename="$2"
@ -1953,7 +1958,11 @@ else
PYTHON_BUILD_DEFAULT_MIRROR= PYTHON_BUILD_DEFAULT_MIRROR=
fi fi
if [ -n "$PYTHON_BUILD_SKIP_MIRROR" ] || ! has_checksum_support compute_sha2; then if [ -n "$PYTHON_BUILD_SKIP_MIRROR" ]; then
unset PYTHON_BUILD_MIRROR_URL
fi
if ! has_checksum_support compute_sha2 && ! [ -n "$PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM" ] ; then
unset PYTHON_BUILD_MIRROR_URL unset PYTHON_BUILD_MIRROR_URL
fi fi

View file

@ -70,6 +70,26 @@ export PYTHON_BUILD_MIRROR_URL=http://mirror.example.com
unstub shasum unstub shasum
} }
@test "package is fetched from mirror when checksum is invalid if SKIP_CHECKSUM set" {
export PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM=1
export PYTHON_BUILD_MIRROR_URL=https://custom.mirror.org
export URL_BASE=example.com
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub shasum false
stub curl "-*I* : true" \
"-q -o * -*S* https://custom.mirror.org/* : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
unset PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM
}
@test "package is fetched from original URL if mirror download checksum is invalid" { @test "package is fetched from original URL if mirror download checksum is invalid" {
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"