-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the error message when bundled pip cannot be found
The Python stdlib bundles a copy of pip, which the buildpack uses to bootstrap the real pip installation. This copy of pip should always exist, and thus not finding it is treated as an internal error. However, via Honeycomb I discovered one app that manages to hit this case regardless, and when it does so, the error message is not the "internal error" error message, but instead a Bash unbound variable error like: ``` -----> Using Python 3.9.20 specified in .python-version -----> Using cached install of Python 3.9.20 /tmp/buildpack/lib/utils.sh: line 33: bundled_pip_wheel_list[0]: unbound variable ``` I believe the reason for pip not being found in this case is that the app source has a broken/EOL Python install committed to it (which doesn't include the `ensurepip` module), which tricks the cache restoration into thinking it can re-use the cache. I will be adding an explicit warning/error for finding an existing `.heroku/python/` directory in the app in a later PR, however, for now this change: (a) fixes the display of the internal error message, (b) adds more debugging output to the error message so that I can confirm my theory as to the root cause for this app. Towards #1710. GUS-W-17386432.
- Loading branch information
Showing
7 changed files
with
61 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This file emulates a Python install having been committed to the app's Git repo. | ||
# For example, by downloading a slug, extracting it, and committing the results. | ||
|
||
set -euo pipefail | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.13 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../spec_helper' | ||
|
||
RSpec.describe 'Buildpack validation checks' do | ||
context 'when the app source contains a broken Python install' do | ||
let(:app) { Hatchet::Runner.new('spec/fixtures/python_in_app_source', allow_failure: true) } | ||
|
||
it 'fails detection' do | ||
app.deploy do |app| | ||
expect(clean_output(app.output)).to include(<<~OUTPUT) | ||
remote: -----> Python app detected | ||
remote: -----> Using Python #{DEFAULT_PYTHON_MAJOR_VERSION} specified in .python-version | ||
remote: -----> Using cached install of Python #{DEFAULT_PYTHON_FULL_VERSION} | ||
remote: | ||
remote: ! Internal Error: Unable to locate the bundled copy of pip. | ||
remote: ! | ||
remote: ! The Python buildpack could not locate the copy of pip bundled | ||
remote: ! inside Python's 'ensurepip' module: | ||
remote: ! | ||
remote: ! find: ‘/app/.heroku/python/lib/python3.13/ensurepip/_bundled/’: No such file or directory | ||
remote: ! /app/.heroku/python/ | ||
remote: ! /app/.heroku/python/bin | ||
remote: | ||
remote: ! Push rejected, failed to compile Python app. | ||
OUTPUT | ||
end | ||
end | ||
end | ||
end |