-
Notifications
You must be signed in to change notification settings - Fork 3
/
python
executable file
·92 lines (77 loc) · 4.17 KB
/
python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
# shellcheck disable=SC2154 # TODO: Env var is referenced but not assigned.
set -euo pipefail
# The Python runtime archive filename is of form: 'python-X.Y.Z-ubuntu-22.04-amd64.tar.zst'
# The Ubuntu version is calculated from `STACK` since it's faster than calling `lsb_release`.
UBUNTU_VERSION="${STACK/heroku-/}.04"
ARCH=$(dpkg --print-architecture)
PYTHON_URL="${S3_BASE_URL}/python-${python_full_version}-ubuntu-${UBUNTU_VERSION}-${ARCH}.tar.zst"
# The Python version validation earlier will have filtered out most unsupported versions.
# However, the version might still not be found if either:
# 1. It's a Python major version we've deprecated and so is only available on older stacks (i.e: Python 3.8).
# 2. If an exact Python version was requested and the patch version doesn't exist (e.g. 3.12.999).
# 3. The user has pinned to an older buildpack version and the S3 bucket location or layout has changed since.
# TODO: Update this message to be more specific once Python 3.8 support is dropped.
if ! curl --output /dev/null --silent --head --fail --retry 3 --retry-connrefused --connect-timeout 10 "${PYTHON_URL}"; then
output::error <<-EOF
Error: Python ${python_full_version} isn't available for this stack (${STACK}).
For a list of the supported Python versions, see:
https://devcenter.heroku.com/articles/python-support#supported-runtimes
EOF
meta_set "failure_reason" "python-version-not-found"
exit 1
fi
if [[ -f "${BUILD_DIR}/.heroku/python/bin/python" ]]; then
output::step "Using cached install of Python ${python_full_version}"
else
output::step "Installing Python ${python_full_version}"
mkdir -p "${BUILD_DIR}/.heroku/python"
if ! curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 10 "${PYTHON_URL}" | tar --zstd --extract --directory "${BUILD_DIR}/.heroku/python"; then
# The Python version was confirmed to exist previously, so any failure here is due to
# a networking issue or archive/buildpack bug rather than the runtime not existing.
output::error <<-EOF
Error: Failed to download/install Python ${python_full_version}.
In some cases, this happens due to an unstable network connection.
Please try again and to see if the error resolves itself.
EOF
meta_set "failure_reason" "python-download"
exit 1
fi
hash -r
fi
function warn_if_patch_update_available() {
local requested_full_version="${1}"
local requested_major_version="${2}"
local latest_patch_version
latest_patch_version="$(python_version::resolve_python_version "${requested_major_version}" "${python_version_origin}")"
# Extract the patch version component of the version strings (ie: the '5' in '3.10.5').
local requested_patch_number="${requested_full_version##*.}"
local latest_patch_number="${latest_patch_version##*.}"
# TODO: Update this message to suggest using the .python-version major version syntax to stay up to date,
# once runtime.txt is deprecated and sticky-versioning only pins to the major version.
if ((requested_patch_number < latest_patch_number)); then
output::warning <<-EOF
Warning: A Python security update is available!
Upgrade as soon as possible to: Python ${latest_patch_version}
See: https://devcenter.heroku.com/articles/python-runtimes
EOF
meta_set "python_version_outdated" "true"
else
meta_set "python_version_outdated" "false"
fi
}
# We wait until now to display outdated Python version warnings, since we only want to show them
# if there weren't any errors with the version to avoid adding noise to the error messages.
# TODO: Move this into lib/ as part of the warnings refactor.
if [[ "${python_major_version}" == "3.8" ]]; then
output::warning <<-'EOF'
Warning: Support for Python 3.8 is ending soon!
Python 3.8 will reach its upstream end-of-life in October 2024, at which
point it will no longer receive security updates:
https://devguide.python.org/versions/#supported-versions
Support for Python 3.8 will be removed from this buildpack on December 4th, 2024.
Upgrade to a newer Python version as soon as possible to keep your app secure.
See: https://devcenter.heroku.com/articles/python-runtimes
EOF
fi
warn_if_patch_update_available "${python_full_version}" "${python_major_version}"