Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Commit 1cb8f1c

Browse files
edmorleydryan
authored andcommitted
Install pip using itself rather than get-pip.py (heroku#1007)
`get-pip.py` is no longer used, since: - It uses `--force-reinstall`, which is unnecessary here and slows down repeat builds (given we call pip install every time now). Trying to work around this by using `get-pip.py` only for the initial install, and real pip for subsequent updates would mean we lose protection against cached broken installs, plus significantly increase the version combinations test matrix. - It means downloading pip twice (once embedded in `get-pip.py`, and again during the install, since `get-pip.py` can't install the embedded version directly). - We would still have to manage several versions of `get-pip.py`, to support older Pythons (once we upgrade to newer pip). We don't use `ensurepip` since: - not all of the previously generated Python runtimes on S3 include it. - we would still have to upgrade pip/setuptools afterwards. - the versions of pip/setuptools bundled with ensurepip differ greatly depending on Python version, and we could easily start using a CLI flag for the first pip install before upgrade that isn't supported on all versions, without even knowing it (unless we test against hundreds of Python archives). Instead we install pip using itself in wheel form. See: pypa/pip#2351 (comment) The new pip wheel assets on S3 were generated using: ``` $ pip download --no-cache pip==19.1.1 Collecting pip==19.1.1 Downloading pip-19.1.1-py2.py3-none-any.whl (1.4 MB) Saved ./pip-19.1.1-py2.py3-none-any.whl Successfully downloaded pip $ pip download --no-cache pip==20.0.2 Collecting pip==20.0.2 Downloading pip-20.0.2-py2.py3-none-any.whl (1.4 MB) Saved ./pip-20.0.2-py2.py3-none-any.whl Successfully downloaded pip $ aws s3 sync . s3://lang-python/common/ --exclude "*" --include "*.whl" --acl public-read --dryrun (dryrun) upload: ./pip-19.1.1-py2.py3-none-any.whl to s3://lang-python/common/pip-19.1.1-py2.py3-none-any.whl (dryrun) upload: ./pip-20.0.2-py2.py3-none-any.whl to s3://lang-python/common/pip-20.0.2-py2.py3-none-any.whl $ aws s3 sync . s3://lang-python/common/ --exclude "*" --include "*.whl" --acl public-read upload: ./pip-19.1.1-py2.py3-none-any.whl to s3://lang-python/common/pip-19.1.1-py2.py3-none-any.whl upload: ./pip-20.0.2-py2.py3-none-any.whl to s3://lang-python/common/pip-20.0.2-py2.py3-none-any.whl ```
1 parent e805cb1 commit 1cb8f1c

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- For repeat builds, also manage the installed versions of setuptools/wheel, rather than just that of pip (#1007).
66
- Install an explicit version of wheel rather than the latest release at the time (#1007).
77
- Output the installed version of pip, setuptools and wheel in the build log (#1007).
8+
- Install pip using itself rather than `get-pip.py` (#1007).
89
- Install setuptools from PyPI rather than a vendored copy (#1007).
910
- Reduce the number of environment variables exposed to `bin/{pre,post}_compile` and other subprocesses (#1011)
1011

bin/steps/README.MD

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

33
TODO: Add context on Python install steps, such as why symlinking vs copying
44

5-
## Installing the Pip tool
6-
7-
The Python Buildpack uses a tool called `get-pip` to install the pip tool. This
8-
is done in the `python` script.
9-
10-
This is in part because Python historically did not come with pip by default.
11-
125
## Installing Python packages using Pip
136

147
### Convention: Use `python` process to invoke Pip

bin/steps/python

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,36 @@ if [[ "${PYTHON_VERSION}" == ${PY34}* ]]; then
145145
WHEEL_VERSION='0.33.6'
146146
fi
147147

148+
# We don't use get-pip.py, since:
149+
# - it uses `--force-reinstall`, which is unnecessary here and slows down repeat builds
150+
# - it means downloading pip twice (once embedded in get-pip.py, and again during
151+
# the install, since get-pip.py can't install the embedded version directly)
152+
# - we would still have to manage several versions of get-pip.py, to support older Pythons.
153+
# Instead, we use the pip wheel to install itself, using the method described here:
154+
# https://github.com/pypa/pip/issues/2351#issuecomment-69994524
155+
PIP_WHEEL_FILENAME="pip-${PIP_VERSION}-py2.py3-none-any.whl"
156+
PIP_WHEEL_URL="https://lang-python.s3.amazonaws.com/common/${PIP_WHEEL_FILENAME}"
157+
PIP_WHEEL="${TMPDIR:-/tmp}/${PIP_WHEEL_FILENAME}"
158+
159+
if ! curl -sSf "${PIP_WHEEL_URL}" -o "$PIP_WHEEL"; then
160+
mcount "failure.python.download-pip"
161+
puts-warn "Failed to download pip"
162+
exit 1
163+
fi
164+
148165
if [[ -f "$BUILD_DIR/Pipfile" ]]; then
149166
# The buildpack is pinned to old pipenv, which requires older pip.
167+
# Pip 9.0.2 doesn't support installing itself from a wheel, so we have to use split
168+
# versions here (ie: installer pip version different from target pip version).
150169
PIP_VERSION='9.0.2'
151-
fi
152-
153-
# Heroku uses the get-pip utility maintained by the Python community to vendor Pip.
154-
# https://github.com/pypa/get-pip
155-
GETPIP_URL="https://lang-python.s3.amazonaws.com/etc/get-pip.py"
156-
GETPIP_PY="${TMPDIR:-/tmp}/get-pip.py"
157-
158-
if ! curl -s "${GETPIP_URL}" -o "$GETPIP_PY" &> /dev/null; then
159-
mcount "failure.python.get-pip"
160-
echo "Failed to pull down get-pip"
161-
exit 1
170+
PIP_TO_INSTALL="pip==${PIP_VERSION}"
171+
else
172+
PIP_TO_INSTALL="${PIP_WHEEL}"
162173
fi
163174

164175
puts-step "Installing pip ${PIP_VERSION}, setuptools ${SETUPTOOLS_VERSION} and wheel ${WHEEL_VERSION}"
165176

166-
/app/.heroku/python/bin/python "$GETPIP_PY" pip=="${PIP_VERSION}" "setuptools==${SETUPTOOLS_VERSION}" "wheel==${WHEEL_VERSION}" &> /dev/null
177+
/app/.heroku/python/bin/python "${PIP_WHEEL}/pip" install "${PIP_TO_INSTALL}" "setuptools==${SETUPTOOLS_VERSION}" "wheel==${WHEEL_VERSION}" &> /dev/null
167178

168179
set -e
169180
hash -r

0 commit comments

Comments
 (0)