]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
adds a utility script that other jobs can use to install python packages
authorAndrew Schoen <aschoen@redhat.com>
Thu, 12 Nov 2015 16:07:19 +0000 (10:07 -0600)
committerAndrew Schoen <aschoen@redhat.com>
Thu, 12 Nov 2015 16:47:04 +0000 (10:47 -0600)
Signed-off-by: Andrew Schoen <aschoen@redhat.com>
scripts/build_utils.sh [new file with mode: 0644]

diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh
new file mode 100644 (file)
index 0000000..812ed27
--- /dev/null
@@ -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
+}