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
This commit is contained in:
Monty Taylor 2020-03-19 15:22:56 -05:00
parent 90fa9170dd
commit cee7903827
2 changed files with 20 additions and 7 deletions

View File

@ -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

View File

@ -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