From 40805875381438e7d3b49456b2e4d8e97feb83b5 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Tue, 28 Jul 2020 21:07:59 +0100 Subject: [PATCH] Move Pip version handling to bin/steps/python (#1007) And use the `$PYTHON_VERSION` calculated in `bin/steps/python` instead of re-implementing the Python version handling. --- bin/compile | 20 -------------------- bin/steps/python | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/bin/compile b/bin/compile index dd270d802..9a0a2d6f6 100755 --- a/bin/compile +++ b/bin/compile @@ -65,26 +65,6 @@ PYPY36="pypy3.6" # Which stack is used (for binary downloading), if none is provided (e.g. outside of Heroku)? DEFAULT_PYTHON_STACK="cedar-14" -# If pip doesn't match this version (the version we install), run the installer. -PIP_UPDATE="20.0.2" - -for file in "$BUILD_DIR/runtime.txt" "$CACHE_DIR/.heroku/python-version" ; do - [ -f "$file" ] || continue - - version=$(tr -d '[:space:]' < "$file") - - case "$version" in "$PY34"*) - # Python 3.4 support was dropped in pip >= 19.2. - PIP_UPDATE="19.1.1" - break - ;; - esac -done - -if [[ -f "$BUILD_DIR/Pipfile" ]]; then - # Do not force pipenv users to re-install pipenv locally. - PIP_UPDATE="9.0.2" -fi # Common Problem Warnings: # This section creates a temporary file in which to stick the output of `pip install`. diff --git a/bin/steps/python b/bin/steps/python index 23a1850b9..5129f5b36 100755 --- a/bin/steps/python +++ b/bin/steps/python @@ -136,6 +136,18 @@ if [ ! "$SKIP_INSTALL" ]; then hash -r fi +PIP_VERSION='20.0.2' + +if [[ "${PYTHON_VERSION}" == ${PY34}* ]]; then + # Python 3.4 support was dropped in pip 19.2+. + PIP_VERSION='19.1.1' +fi + +if [[ -f "$BUILD_DIR/Pipfile" ]]; then + # The buildpack is pinned to old pipenv, which requires older pip. + PIP_VERSION='9.0.2' +fi + # Heroku uses the get-pip utility maintained by the Python community to vendor Pip. # https://github.com/pypa/get-pip GETPIP_URL="https://lang-python.s3.amazonaws.com/etc/get-pip.py" @@ -148,15 +160,15 @@ if ! curl -s "${GETPIP_URL}" -o "$GETPIP_PY" &> /dev/null; then fi # If a new Python has been installed or Pip isn't up to date: -if [ "$FRESH_PYTHON" ] || [[ ! $(pip --version) == *$PIP_UPDATE* ]]; then +if [ "$FRESH_PYTHON" ] || [[ ! $(pip --version) == *${PIP_VERSION}* ]]; then - puts-step "Installing pip ${PIP_UPDATE}" + puts-step "Installing pip ${PIP_VERSION}" # Remove old installations. rm -fr /app/.heroku/python/lib/python*/site-packages/pip-* rm -fr /app/.heroku/python/lib/python*/site-packages/setuptools-* - /app/.heroku/python/bin/python "$GETPIP_PY" pip=="$PIP_UPDATE" &> /dev/null + /app/.heroku/python/bin/python "$GETPIP_PY" pip=="${PIP_VERSION}" &> /dev/null /app/.heroku/python/bin/pip install "$ROOT_DIR/vendor/setuptools-39.0.1-py2.py3-none-any.whl" &> /dev/null fi