From: Thanh Ha Date: Wed, 30 Aug 2017 23:08:53 +0000 (-0400) Subject: Add lf-pip-install macro to handle pypi packages X-Git-Tag: v0.8.0~3^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=3eafac9054bf588d14eefe4c72d0e9034b8ce6e6;p=releng%2Fglobal-jjb.git Add lf-pip-install macro to handle pypi packages This creates a generically reusable pip-install macro that can be used to install pypi packages into a virtualenv. The script uses the first package name from {pip-packages} as the name of the virtualenv it creates. Change-Id: Iabe4005efcb0a79af48d3c83d854f4e101414737 Signed-off-by: Thanh Ha --- diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index bc9901d3..1c580624 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -165,6 +165,15 @@ - file-id: '{settings-file}' variable: 'SETTINGS_FILE' +- builder: + name: lf-pip-install + # Call pip install to install packages into a virtualenv + # The first package listed in PIP_PACKAGES is used as the virtualenv name. + builders: + - inject: + properties-content: PIP_PACKAGES={pip-packages} + - shell: !include-raw-escape: ../shell/pip-install.sh + - builder: name: lf-provide-maven-settings-cleanup # Clear maven settings files after we are done using them diff --git a/shell/pip-install.sh b/shell/pip-install.sh new file mode 100644 index 00000000..b2aacfe8 --- /dev/null +++ b/shell/pip-install.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2017 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## +# pip install packages into a virtualenv using the first listed package as venv name +# +# PIP_PACKAGES is a space separated list of pypi packages to install. The first +# listed package is used as the virtualenv directory name. +echo "---> pip-install.sh" + +# Ensure we fail the job if any steps fail. +# DO NOT set -u as virtualenv's activate script has unbound variables +set -e -o pipefail + +# Install git-review using virtualenv to the latest version that supports +# --reviewers option, available through pip install. Existing minion image has a +# version that does not have it. +virtualenv "/tmp/v/${PIP_PACKAGES%% *}" +# shellcheck source=/tmp/v/venv/bin/activate disable=SC1091 +source "/tmp/v/${PIP_PACKAGES%% *}/bin/activate" +pip install --quiet --upgrade pip +pip install --quiet --upgrade pipdeptree + +# PIP_PACKAGES needs to be passed through as a space separated list of packages +# shellcheck disable=SC2086 +pip install --upgrade $PIP_PACKAGES + +echo "----> Pip Dependency Tree" +pipdeptree