From cee7903827dc9639597ad9d0ba264cb9c189e74b Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 19 Mar 2020 15:22:56 -0500 Subject: [PATCH] Add constraints support to python-builder If someone drops an upper-constraints.txt into the source dir, add it to the pip interactions. Change-Id: I6b3c2a178d6fd9ee19918657c809ebf100a7724b --- docker/python-builder/scripts/assemble | 15 +++++++++++---- docker/python-builder/scripts/install-from-bindep | 12 +++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/docker/python-builder/scripts/assemble b/docker/python-builder/scripts/assemble index 6b314170c8..7e1ebab8f1 100755 --- a/docker/python-builder/scripts/assemble +++ b/docker/python-builder/scripts/assemble @@ -60,16 +60,16 @@ function install_wheels { # Only do this for the main package (i.e. only write requirements # once). if [ -f /tmp/src/requirements.txt ] && [ ! -f /output/requirements.txt ] ; then - /tmp/venv/bin/pip install --cache-dir=/output/wheels -r /tmp/src/requirements.txt + /tmp/venv/bin/pip install $CONSTRAINTS --cache-dir=/output/wheels -r /tmp/src/requirements.txt cp /tmp/src/requirements.txt /output/requirements.txt fi - /tmp/venv/bin/pip install --cache-dir=/output/wheels /output/wheels/*whl + /tmp/venv/bin/pip install $CONSTRAINTS --cache-dir=/output/wheels /output/wheels/*whl # Install each of the extras so that we collect all possibly # needed wheels in the wheel cache. get-extras-packages also # writes out the req files into /output/$extra/requirements.txt. for req in $(get-extras-packages) ; do - /tmp/venv/bin/pip install --cache-dir=/output/wheels "$req" + /tmp/venv/bin/pip install $CONSTRAINTS --cache-dir=/output/wheels "$req" done } @@ -90,10 +90,17 @@ done python -m venv /tmp/venv /tmp/venv/bin/pip install -U pip wheel +# If there is an upper-constraints.txt file in the source tree, +# use it in the pip commands. +if [ -f /tmp/src/upper-constraints.txt ] ; then + cp /tmp/src/upper-constraints.txt /output/upper-constraints.txt + CONSTRAINTS="-c /tmp/src/upper-constraints.txt" +fi + # If we got a list of packages, install them, otherwise install the # main package. if [[ $PACKAGES ]] ; then - /tmp/venv/bin/pip install --cache-dir=/output/wheels $PACKAGES + /tmp/venv/bin/pip install $CONSTRAINTS --cache-dir=/output/wheels $PACKAGES for package in $PACKAGES ; do echo "$package" >> /output/packages.txt done diff --git a/docker/python-builder/scripts/install-from-bindep b/docker/python-builder/scripts/install-from-bindep index 35cc1664a3..2289c4991f 100755 --- a/docker/python-builder/scripts/install-from-bindep +++ b/docker/python-builder/scripts/install-from-bindep @@ -18,12 +18,18 @@ set -e apt-get update apt-get -y install $(cat /output/bindep/run.txt) + +# If there's a constraints file, use it. +if [ -f /output/upper-constraints.txt ] ; then + CONSTRAINTS="-c /output/upper-constraints.txt" +fi + # If a requirements.txt file exists, # install it directly so that people can use git url syntax # to do things like pick up patched but unreleased versions # of dependencies. if [ -f /output/requirements.txt ] ; then - pip install --cache-dir=/output/wheels -r /output/requirements.txt + pip install $CONSTRAINTS --cache-dir=/output/wheels -r /output/requirements.txt fi # Add any requested extras to the list of things to install @@ -35,13 +41,13 @@ done if [ -f /output/packages.txt ] ; then # If a package list was passed to assemble, install that in the final # image. - pip install --cache-dir=/output/wheels -r /output/packages.txt $EXTRAS + pip install $CONSTRAINTS --cache-dir=/output/wheels -r /output/packages.txt $EXTRAS else # Install the wheels. Use --force here because sibling wheels might # be built with the same version number as the latest release, but we # really want the speculatively built wheels installed over any # automatic dependencies. - pip install --force --cache-dir=/output/wheels /output/wheels/*.whl $EXTRAS + pip install $CONSTRAINTS --force --cache-dir=/output/wheels /output/wheels/*.whl $EXTRAS fi # clean up after ourselves