From 53c4674ecd9f99029cf89f379a5083057415e6ab Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Wed, 21 Aug 2019 18:17:40 +0200 Subject: [PATCH 1/4] Upgrade to pip 19.2.3 Bump PIP_UPDATE from 9.0.2 to 19.2.3. This variable is used in bin/steps/python to determine which pip version to install or upgrade to. --- bin/compile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/compile b/bin/compile index 9319463af..fc3d82fd2 100755 --- a/bin/compile +++ b/bin/compile @@ -62,7 +62,7 @@ PY27="python-2.7" # 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="9.0.2" +PIP_UPDATE="19.2.3" export DEFAULT_PYTHON_STACK PIP_UPDATE export PY37 PY36 PY35 PY27 PY34 From 515a222cc451c2b7d656f702c6a396c0e6ec407d Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Thu, 22 Aug 2019 19:31:17 +0200 Subject: [PATCH 2/4] Upgrade to pip 19.1.1 for Python 3.4 projects Python 3.4 support was dropped in pip >= 19.2. For projects still on this Python version, use pip 19.1.1 instead of pip 19.2.1. --- bin/compile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bin/compile b/bin/compile index fc3d82fd2..5a0292e5a 100755 --- a/bin/compile +++ b/bin/compile @@ -64,6 +64,19 @@ DEFAULT_PYTHON_STACK="cedar-14" # If pip doesn't match this version (the version we install), run the installer. PIP_UPDATE="19.2.3" +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 + export DEFAULT_PYTHON_STACK PIP_UPDATE export PY37 PY36 PY35 PY27 PY34 From 468d27ab98e735fe0846c131d39135d6bb82d866 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Thu, 22 Aug 2019 14:13:45 +0200 Subject: [PATCH 3/4] Adapt pip-pop to changes in pip >= 10 The pip-diff and pip-grep tools from the vendorized `pip-pop` package import internal modules from pip. In pip >= 10, internal modules were moved under `pip._internal`, breaking the imports. Use `try...except ImportError` to handle both import paths. Also, the interface of the `PackageFinder` class from one of these modules changed. Provide a wrapper function to allow creating objects of this type using the old interface. --- vendor/pip-pop/pip-diff | 21 ++++++++++++++++++--- vendor/pip-pop/pip-grep | 22 +++++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/vendor/pip-pop/pip-diff b/vendor/pip-pop/pip-diff index 2bb1877c8..8fc7d6f98 100755 --- a/vendor/pip-pop/pip-diff +++ b/vendor/pip-pop/pip-diff @@ -12,9 +12,24 @@ Options: """ import os from docopt import docopt -from pip.req import parse_requirements -from pip.index import PackageFinder -from pip._vendor.requests import session + +try: # pip >= 10 + from pip._internal.req import parse_requirements + from pip._internal.download import PipSession as session + + def PackageFinder(find_links, index_urls, session=None): + from pip._internal.index import PackageFinder + from pip._internal.models.search_scope import SearchScope + from pip._internal.models.selection_prefs import SelectionPreferences + + search_scope = SearchScope.create(find_links, index_urls) + selection_prefs = SelectionPreferences(allow_yanked=False) + return PackageFinder.create(search_scope, selection_prefs, session=session) + +except ImportError: # pip <= 9.0.3 + from pip.req import parse_requirements + from pip.index import PackageFinder + from pip._vendor.requests import session requests = session() diff --git a/vendor/pip-pop/pip-grep b/vendor/pip-pop/pip-grep index d55000ad8..8e3cf6111 100755 --- a/vendor/pip-pop/pip-grep +++ b/vendor/pip-pop/pip-grep @@ -10,9 +10,25 @@ Options: import os import sys from docopt import docopt -from pip.req import parse_requirements -from pip.index import PackageFinder -from pip._vendor.requests import session + +try: # pip >= 10 + from pip._internal.req import parse_requirements + from pip._internal.download import PipSession as session + + def PackageFinder(find_links, index_urls, session=None): + from pip._internal.index import PackageFinder + from pip._internal.models.search_scope import SearchScope + from pip._internal.models.selection_prefs import SelectionPreferences + + search_scope = SearchScope.create(find_links, index_urls) + selection_prefs = SelectionPreferences(allow_yanked=False) + return PackageFinder.create(search_scope, selection_prefs, session=session) + +except ImportError: # pip <= 9.0.3 + from pip.req import parse_requirements + from pip.index import PackageFinder + from pip._vendor.requests import session + requests = session() From 8eb2954e92942979e57c6ca80b093b7eb6b50b64 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Thu, 3 Oct 2019 16:47:29 +0200 Subject: [PATCH 4/4] Pin to pip 9.0.2 for pipenv users only This addresses an issue raised by @CaseyFeist during code review: Updating pip for pipenv users or requiring them to update without a heads up won't be a good experience (our version is old enough that they'll need to uninstall and reinstall pipenv locally to successfully update). If you can refactor this to stay pinned to current version for pipenv users only, I should be able to accept this (and the related project updates). https://github.com/heroku/heroku-buildpack-python/pull/833#issuecomment-537758441 --- bin/compile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/compile b/bin/compile index 5a0292e5a..db2d838bb 100755 --- a/bin/compile +++ b/bin/compile @@ -77,6 +77,11 @@ for file in "$BUILD_DIR/runtime.txt" "$CACHE_DIR/.heroku/python-version" ; do esac done +if [[ -f "$BUILD_DIR/Pipfile" ]]; then + # Do not force pipenv users to re-install pipenv locally. + PIP_UPDATE="9.0.2" +fi + export DEFAULT_PYTHON_STACK PIP_UPDATE export PY37 PY36 PY35 PY27 PY34