Skip to content

Commit

Permalink
Improve package manager bootstrap error messages
Browse files Browse the repository at this point in the history
* Any errors are now indented using the same indent helper
  used for other buildpack subprocesses.
* Adds "temporary network issue" verbiage based on that now
  used for the Python runtime download step.
  • Loading branch information
edmorley committed Feb 24, 2025
1 parent 25172f4 commit 5932e54
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Improved the error messages shown if installing pip/Poetry/Pipenv fails. ([#1764](https://github.com/heroku/heroku-buildpack-python/pull/1764))
- Stopped installing pip into Poetry's virtual environment. ([#1761](https://github.com/heroku/heroku-buildpack-python/pull/1761))

## [v278] - 2025-02-24
Expand Down
10 changes: 7 additions & 3 deletions lib/pip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,26 @@ function pip::install_pip_setuptools_wheel() {
# app's requirements.txt in the last build). The install will be a no-op if the versions match.
output::step "Installing ${packages_display_text}"

# shellcheck disable=SC2310 # This function is invoked in an 'if' condition so set -e will be disabled.
if ! {
python "${bundled_pip_module_path}" \
install \
--disable-pip-version-check \
--no-cache-dir \
--no-input \
--quiet \
"${packages_to_install[@]}"
"${packages_to_install[@]}" \
|& output::indent
}; then
output::error <<-EOF
Error: Unable to install pip.
In some cases, this happens due to a temporary issue with
the network connection or Python Package Index (PyPI).
Try building again to see if the error resolves itself.
If that does not help, check the status of PyPI (the Python
package repository service), here:
If that does not help, check the status of PyPI here:
https://status.python.org
EOF
meta_set "failure_reason" "install-package-manager::pip"
Expand Down
11 changes: 8 additions & 3 deletions lib/pipenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ function pipenv::install_pipenv() {
# TODO: Install Pipenv into a venv so it isn't leaked into the app environment.
# TODO: Skip installing Pipenv if its version hasn't changed (once it's installed into a venv).
# TODO: Explore viability of making Pipenv only be available during the build, to reduce slug size.

# shellcheck disable=SC2310 # This function is invoked in an 'if' condition so set -e will be disabled.
if ! {
pip \
install \
--disable-pip-version-check \
--no-cache-dir \
--no-input \
--quiet \
"pipenv==${PIPENV_VERSION}"
"pipenv==${PIPENV_VERSION}" \
|& output::indent
}; then
output::error <<-EOF
Error: Unable to install Pipenv.
In some cases, this happens due to a temporary issue with
the network connection or Python Package Index (PyPI).
Try building again to see if the error resolves itself.
If that does not help, check the status of PyPI (the Python
package repository service), here:
If that does not help, check the status of PyPI here:
https://status.python.org
EOF
meta_set "failure_reason" "install-package-manager::pipenv"
Expand Down
13 changes: 9 additions & 4 deletions lib/poetry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function poetry::install_poetry() {
# it bundles its own copy for use as a fallback. As such we don't need to install pip
# into the Poetry venv (and in fact, Poetry wouldn't use this install anyway, since
# it only finds an external pip if it exists in the target venv).
if ! python -m venv --without-pip "${poetry_venv_dir}"; then
# shellcheck disable=SC2310 # This function is invoked in an 'if' condition so set -e will be disabled.
if ! python -m venv --without-pip "${poetry_venv_dir}" |& output::indent; then
output::error <<-EOF
Internal Error: Unable to create virtual environment for Poetry.
Expand All @@ -65,22 +66,26 @@ function poetry::install_poetry() {
# We must call the venv Python directly here, rather than relying on pip's `--python`
# option, since `--python` was only added in pip v22.3, so isn't supported by the older
# pip versions bundled with Python 3.9/3.10.
# shellcheck disable=SC2310 # This function is invoked in an 'if' condition so set -e will be disabled.
if ! {
"${poetry_venv_dir}/bin/python" "${bundled_pip_module_path}" \
install \
--disable-pip-version-check \
--no-cache-dir \
--no-input \
--quiet \
"poetry==${POETRY_VERSION}"
"poetry==${POETRY_VERSION}" \
|& output::indent
}; then
output::error <<-EOF
Error: Unable to install Poetry.
In some cases, this happens due to a temporary issue with
the network connection or Python Package Index (PyPI).
Try building again to see if the error resolves itself.
If that does not help, check the status of PyPI (the Python
package repository service), here:
If that does not help, check the status of PyPI here:
https://status.python.org
EOF
meta_set "failure_reason" "install-package-manager::poetry"
Expand Down

0 comments on commit 5932e54

Please sign in to comment.