From a17089d199af910eb2d91c7b29d399dc3f42f14c Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Thu, 12 Nov 2015 10:07:19 -0600 Subject: [PATCH] adds a utility script that other jobs can use to install python packages Signed-off-by: Andrew Schoen --- scripts/build_utils.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 scripts/build_utils.sh diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh new file mode 100644 index 00000000..812ed276 --- /dev/null +++ b/scripts/build_utils.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -ex + +VENV="$WORKSPACE/venv/bin" + +install_python_packages () { + # Use this function to create a virtualenv and install + # python packages. Pass either a single package name or a list + # of package names. Usage: + # + # install_python_packages "ansible" + # + # to_install=( "ansible" "chacractl>=0.0.4" ) + # install_python_packages "to_install[@]" + # + # Create the virtualenv + virtualenv $WORKSPACE/venv + + # Define and ensure the PIP cache + PIP_SDIST_INDEX="$HOME/.cache/pip" + mkdir -p $PIP_SDIST_INDEX + + pkgs=("${!1}") + for package in ${pkgs[@]}; do + echo $package + # download packages to the local pip cache + $VENV/pip install --upgrade --exists-action=i --download="$PIP_SDIST_INDEX" $package + # install packages from the local pip cache, ignoring pypi + $VENV/pip install --upgrade --exists-action=i --find-links="file://$PIP_SDIST_INDEX" --no-index $package + done +} -- 2.39.5