Skip to content

Commit 4a264fc

Browse files
authored
Enable Bash exit on undefined variables (set -u) (#1646)
Since it's a best practice that helps make bugs more visible. Aside from the `DEBUG_COLLECTSTATIC` change, all of the others only affect buildpack internals. GUS-W-16864420.
1 parent 92c9328 commit 4a264fc

File tree

11 files changed

+14
-18
lines changed

11 files changed

+14
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- Fixed Django collectstatic debug output being shown if `DEBUG_COLLECTSTATIC` was set to `0` or the empty string. ([#1646](https://github.com/heroku/heroku-buildpack-python/pull/1646))
56
- Stopped adding a trailing `:` to `C_INCLUDE_PATH`, `CPLUS_INCLUDE_PATH`, `LIBRARY_PATH`, `LD_LIBRARY_PATH` and `PKG_CONFIG_PATH`. ([#1645](https://github.com/heroku/heroku-buildpack-python/pull/1645))
67
- Removed remnants of the unused `.heroku/vendor/` directory. ([#1644](https://github.com/heroku/heroku-buildpack-python/pull/1644))
78

bin/compile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
# Usage: bin/compile <build-dir> <cache-dir> <env-dir>
33
# See: https://devcenter.heroku.com/articles/buildpack-api
44

5-
set -eo pipefail
5+
set -euo pipefail
66

7-
[[ -n "$BUILDPACK_XTRACE" ]] && set -o xtrace
7+
# Note: This can't be enabled via app config vars, since at this point they haven't been loaded from ENV_DIR.
8+
if [[ "${BUILDPACK_XTRACE:-0}" == "1" ]]; then
9+
set -o xtrace
10+
fi
811

912
BUILD_DIR="${1}"
1013
CACHE_DIR="${2}"

bin/release

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)
1212
# Unfortunately the build system doesn't source the `export` script before
1313
# running `bin/release`, so we have to do so manually to ensure the buildpack
1414
# Python is used by `is_module_available` instead of system Python.
15-
# We also have to disable Bash error on undefined variables, since not all env
16-
# vars used in the export script will be set by default (eg `LIBRARY_PATH`).
17-
set +u
1815
# shellcheck source=/dev/null
1916
source "${BUILDPACK_DIR}/export"
20-
set -u
2117

2218
source "${BUILDPACK_DIR}/bin/utils"
2319

bin/report

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)
2626

2727
# The build system doesn't source the `export` script before running this script, so we have to do
2828
# so manually (if it exists) so that buildpack Python/pip can be found (if the build succeeded).
29-
# We have to disable Bash error on undefined variables for now, since not all env vars used in the
30-
# export script will be set by default (eg `LIBRARY_PATH`).
3129
EXPORT_FILE="${BUILDPACK_DIR}/export"
3230
if [[ -f "${EXPORT_FILE}" ]]; then
33-
set +u
3431
# shellcheck source=/dev/null
3532
source "${EXPORT_FILE}"
36-
set -u
3733
fi
3834

3935
source "${BUILDPACK_DIR}/lib/metadata.sh"

bin/steps/collectstatic

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# This script is run in a subshell via sub_env so doesn't inherit the options/vars/utils from `bin/compile`.
1414
# TODO: Stop running this script in a subshell.
15-
set -eo pipefail
15+
set -euo pipefail
1616
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")" && pwd)
1717
source "${BUILDPACK_DIR}/bin/utils"
1818

@@ -92,7 +92,7 @@ echo
9292
echo " https://devcenter.heroku.com/articles/django-assets"
9393

9494
# Additionally, dump out the environment, if debug mode is on.
95-
if [[ -n "$DEBUG_COLLECTSTATIC" ]]; then
95+
if [[ "${DEBUG_COLLECTSTATIC:-0}" == "1" ]]; then
9696
echo
9797
echo "****** Collectstatic environment variables:"
9898
echo

bin/steps/nltk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# This script is run in a subshell via sub_env so doesn't inherit the options/vars/utils from `bin/compile`.
44
# TODO: Stop running this script in a subshell.
5-
set -eo pipefail
5+
set -euo pipefail
66
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")" && pwd)
77
source "${BUILDPACK_DIR}/bin/utils"
88

bin/steps/python

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if [[ -f "${BUILD_DIR}/requirements.txt" ]]; then
144144
fi
145145
fi
146146

147-
if [[ -n "${SKIP_INSTALL}" ]]; then
147+
if [[ "${SKIP_INSTALL:-0}" == "1" ]]; then
148148
puts-step "Using cached install of ${PYTHON_VERSION}"
149149
else
150150
puts-step "Installing ${PYTHON_VERSION}"

bin/steps/sqlite3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
sqlite3_install() {
77
HEROKU_PYTHON_DIR="$1"
8-
HEADERS_ONLY="$3"
8+
HEADERS_ONLY="${3:-}"
99

1010
mkdir -p "$HEROKU_PYTHON_DIR"
1111

lib/pip.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function pip::install_dependencies() {
5252
fi
5353

5454
# Install test dependencies, for Heroku CI.
55-
if [[ -n "${INSTALL_TEST}" ]]; then
55+
if [[ "${INSTALL_TEST:-0}" == "1" ]]; then
5656
if [[ -f requirements-test.txt ]]; then
5757
puts-step "Installing test dependencies..."
5858
/app/.heroku/python/bin/pip install -r requirements-test.txt --exists-action=w --src='/app/.heroku/src' --disable-pip-version-check --no-cache-dir 2>&1 | cleanup | indent

lib/pipenv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function pipenv::install_dependencies() {
3232

3333
# Install the test dependencies, for CI.
3434
# TODO: This is currently inconsistent with the non-test path, since it assumes (but doesn't check for) a lockfile.
35-
if [[ -n "${INSTALL_TEST}" ]]; then
35+
if [[ "${INSTALL_TEST:-0}" == "1" ]]; then
3636
puts-step "Installing test dependencies with Pipenv"
3737
/app/.heroku/python/bin/pipenv install --dev --system --deploy --extra-pip-args='--src=/app/.heroku/src' 2>&1 | cleanup | indent
3838

0 commit comments

Comments
 (0)