mirror of
https://github.com/kennethreitz/heroku-buildpack-python.git
synced 2026-06-05 23:10:16 +00:00
ead59ac7ff
In #1011 the number of buildpack variables that are exported (and so exposed to subprocesses) was reduced, since in general we don't want to leak buildpack internals into end-user steps such as the pre/post compile hooks. However since this change, any buildpack metric emitted from within a `sub_env` wrapper (which is a buildpack-stdlib utility function) is missing its `buildpack.python` prefix. This is because buildpack-stdlib: * lazy-loads `BPLOG_PREFIX` (rather than doing so when initially sourced, which is the approach used for `BUILDPACK_LOG_FILE`) * doesn't check whether `BPLOG_PREFIX` is set before emitting metrics See: https://github.com/heroku/buildpack-stdlib/blob/v8/stdlib.sh As a stop-gap until we either fix this in buildpack-stdlib (W-8095466), or remove usages of the `sub_env` wrapper (since I think they are counter-productive in this buildpack), I've added back the export for `BPLOG_PREFIX`. Fixes @W-8095436@.
161 lines
4.5 KiB
Bash
Executable File
161 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Default Python Versions
|
|
# shellcheck source=bin/default_pythons
|
|
source "bin/default_pythons"
|
|
|
|
testGitEgg() {
|
|
compile "git-egg"
|
|
assertCaptured "requests"
|
|
assertCapturedSuccess
|
|
}
|
|
|
|
testSmartRequirements() {
|
|
local cache_dir="$(mktmpdir)"
|
|
compile "requirements-standard" "$cache_dir"
|
|
assertFile "requests" ".heroku/python/requirements-declared.txt"
|
|
assertCapturedSuccess
|
|
compile "psycopg2" "$cache_dir"
|
|
assertFile "psycopg2" ".heroku/python/requirements-declared.txt"
|
|
assertCapturedSuccess
|
|
}
|
|
|
|
testStackChange() {
|
|
local cache_dir="$(mktmpdir)"
|
|
mkdir -p "${cache_dir}/.heroku"
|
|
echo "different-stack" > "${cache_dir}/.heroku/python-stack"
|
|
compile "requirements-standard" "$cache_dir"
|
|
assertCaptured "clearing cache"
|
|
assertFile "$STACK" ".heroku/python-stack"
|
|
assertCapturedSuccess
|
|
}
|
|
|
|
testSetupPy() {
|
|
compile "setup-py"
|
|
assertCaptured "maya"
|
|
# Can't use `assertCapturedSuccess` since stderr contains:
|
|
# "cp: cannot stat '/tmp/build_*/requirements.txt': No such file or directory" (W-7924941)
|
|
assertCapturedSuccessWithStdErr
|
|
}
|
|
|
|
testStandardRequirements() {
|
|
compile "requirements-standard"
|
|
assertCaptured "requests"
|
|
assertCapturedSuccess
|
|
}
|
|
|
|
testPipenv() {
|
|
compile "pipenv"
|
|
assertCaptured "Installing pip 9.0.2, setuptools 47.1.1 and wheel 0.34.2"
|
|
# Can't use `assertCapturedSuccess` since stderr contains:
|
|
# "cp: cannot stat '/tmp/build_*/requirements.txt': No such file or directory" (W-7924941)
|
|
assertCapturedSuccessWithStdErr
|
|
}
|
|
|
|
testPipenvLock() {
|
|
compile "pipenv-lock"
|
|
# Can't use `assertCapturedSuccess` since stderr contains:
|
|
# "cp: cannot stat '/tmp/build_*/requirements.txt': No such file or directory" (W-7924941)
|
|
assertCapturedSuccessWithStdErr
|
|
}
|
|
|
|
testPipenvPythonVersion3_6() {
|
|
compile "pipenv-version"
|
|
assertCaptured "Installing ${LATEST_36}"
|
|
# Can't use `assertCapturedSuccess` since stderr contains:
|
|
# "cp: cannot stat '/tmp/build_*/requirements.txt': No such file or directory" (W-7924941)
|
|
assertCapturedSuccessWithStdErr
|
|
}
|
|
|
|
testPipenvPythonVersion2_7() {
|
|
# Python 2.7 is EOL, so it has not been built for Heroku-20.
|
|
if [[ $STACK == "heroku-20" ]]; then
|
|
return
|
|
fi
|
|
compile "pipenv-version2"
|
|
assertCaptured "Installing ${LATEST_27}"
|
|
# Can't use `assertCapturedSuccess` since stderr contains:
|
|
# "cp: cannot stat '/tmp/build_*/requirements.txt': No such file or directory" (W-7924941)
|
|
assertCapturedSuccessWithStdErr
|
|
}
|
|
|
|
testPipenvPythonFullVersion() {
|
|
# Python 3.7+ requires newer libssl than is present on Cedar-14.
|
|
if [[ "${STACK}" = "cedar-14" ]]; then
|
|
return
|
|
fi
|
|
compile "pipenv-full-version"
|
|
assertCaptured "3.7.8"
|
|
# Can't use `assertCapturedSuccess` since stderr contains:
|
|
# "cp: cannot stat '/tmp/build_*/requirements.txt': No such file or directory" (W-7924941)
|
|
assertCapturedSuccessWithStdErr
|
|
}
|
|
|
|
testNoRequirements() {
|
|
compile "no-requirements"
|
|
assertCapturedError
|
|
}
|
|
|
|
testWarnOldDjango() {
|
|
compile "old-django"
|
|
assertCaptured "Your Django version is nearing the end of its community support."
|
|
assertCapturedSuccess
|
|
}
|
|
|
|
testDontWarnOldDjango() {
|
|
compile "not-old-django"
|
|
assertNotCaptured "Your Django version is nearing the end of its community support."
|
|
assertCapturedSuccess
|
|
}
|
|
|
|
testHooks() {
|
|
# Test that the hooks are called correctly, and that the environment contains
|
|
# the app's config vars but no unexpected env vars from the buildpack.
|
|
local env_dir="$(mktmpdir)"
|
|
echo 'test' > "${env_dir}/SOME_APP_CONFIG_VAR"
|
|
local expected_env_vars=(
|
|
_
|
|
BIN_DIR
|
|
BPLOG_PREFIX
|
|
BUILD_DIR
|
|
BUILDPACK_LOG_FILE
|
|
CACHE_DIR
|
|
C_INCLUDE_PATH
|
|
CPLUS_INCLUDE_PATH
|
|
ENV_DIR
|
|
EXPORT_PATH
|
|
HOME
|
|
LANG
|
|
LD_LIBRARY_PATH
|
|
LIBRARY_PATH
|
|
OLDPWD
|
|
PATH
|
|
PIP_NO_PYTHON_VERSION_WARNING
|
|
PKG_CONFIG_PATH
|
|
PROFILE_PATH
|
|
PWD
|
|
PYTHONUNBUFFERED
|
|
S3_BASE_URL
|
|
SHLVL
|
|
SOME_APP_CONFIG_VAR
|
|
STACK
|
|
)
|
|
if [[ "${STACK}" == "cedar-14" || "${STACK}" == "heroku-16" ]]; then
|
|
# Remove "OLDPWD" from expected_env_vars since for bash <4.4 it's not exported to subshells:
|
|
# https://github.com/heroku/heroku-buildpack-python/pull/1011#issuecomment-665117835
|
|
read -ra expected_env_vars <<< "${expected_env_vars[@]/OLDPWD/}"
|
|
fi
|
|
compile 'hooks' '' "${env_dir}"
|
|
assertCaptured "pre_compile ran!"
|
|
assertCaptured "pre_compile env: ${expected_env_vars[*]}."
|
|
assertCaptured "post_compile ran!"
|
|
assertCaptured "post_compile env: ${expected_env_vars[*]}."
|
|
assertCapturedSuccess
|
|
}
|
|
|
|
pushd $(dirname 0) >/dev/null
|
|
popd >/dev/null
|
|
|
|
source $(pwd)/test/utils
|
|
source $(pwd)/test/shunit2
|