From 9a3817576be38706c4c29831278f9941b0f78ee6 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Fri, 26 May 2017 16:16:10 +0900 Subject: [PATCH] Use tox_install.sh to handle Depends-On By using zuul-cloner, developers can use Depends-On directive in a commit message to test cross-project dependency. Change-Id: I0c593e2369cdfac17f21c5c0a07d9e73246602d8 --- .../test-requirements.txt | 2 - .../tools/tox_install.sh | 88 +++++++++++++++++++ {{cookiecutter.repo_name}}/tox.ini | 6 +- 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100755 {{cookiecutter.repo_name}}/tools/tox_install.sh diff --git a/{{cookiecutter.repo_name}}/test-requirements.txt b/{{cookiecutter.repo_name}}/test-requirements.txt index d8fbcb5..cd29827 100644 --- a/{{cookiecutter.repo_name}}/test-requirements.txt +++ b/{{cookiecutter.repo_name}}/test-requirements.txt @@ -26,5 +26,3 @@ sphinx!=1.3b1,<1.3,>=1.2.1 # BSD testtools>=1.4.0 # MIT # This also needs xvfb library installed on your OS xvfbwrapper>=0.1.3 #license: MIT -# Include horizon as test requirement -http://tarballs.openstack.org/horizon/horizon-master.tar.gz#egg=horizon diff --git a/{{cookiecutter.repo_name}}/tools/tox_install.sh b/{{cookiecutter.repo_name}}/tools/tox_install.sh new file mode 100755 index 0000000..7fd2a59 --- /dev/null +++ b/{{cookiecutter.repo_name}}/tools/tox_install.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# Client constraint file contains this client version pin that is in conflict +# with installing the client from source. We should remove the version pin in +# the constraints file before applying it for from-source installation. +# The script also has a secondary purpose to install certain special +# dependencies directly from git. + +# Wrapper for pip install that always uses constraints. +function pip_install() { + pip install -c"$localfile" -U "$@" +} + +# Grab the library from git using either zuul-cloner or pip. The former is +# there to a take advantage of the setup done by the gate infrastructure +# and honour any/all Depends-On headers in the commit message +function install_from_git() { + ZUUL_CLONER=/usr/zuul-env/bin/zuul-cloner + # GIT_HOST=git.openstack.org + GIT_HOST=github.com + PROJ=$1 + EGG=$2 + + edit-constraints "$localfile" -- "$EGG" + if [ -x "$ZUUL_CLONER" ]; then + SRC_DIR="$VIRTUAL_ENV/src" + mkdir -p "$SRC_DIR" + cd "$SRC_DIR" >/dev/null + ZUUL_CACHE_DIR=${ZUUL_CACHE_DIR:-/opt/git} $ZUUL_CLONER \ + --branch "$BRANCH_NAME" \ + "git://$GIT_HOST" "$PROJ" + pip_install -e "$PROJ/." + cd - >/dev/null + else + SRC_DIR="$VIRTUAL_ENV/src/$PROJ" + git clone --depth 1 --branch $BRANCH_NAME https://$GIT_HOST/$PROJ $SRC_DIR + pip_install -e $SRC_DIR + fi +} + + + +CONSTRAINTS_FILE="$1" +shift 1 + +# This script will either complete with a return code of 0 or the return code +# of whatever failed. +set -e + +# NOTE(tonyb): Place this in the tox environment's log dir so it will get +# published to logs.openstack.org for easy debugging. +mkdir -p "$VIRTUAL_ENV/log/" +localfile="$VIRTUAL_ENV/log/upper-constraints.txt" + +if [[ "$CONSTRAINTS_FILE" != http* ]]; then + CONSTRAINTS_FILE="file://$CONSTRAINTS_FILE" +fi +# NOTE(tonyb): need to add curl to bindep.txt if the project supports bindep +curl "$CONSTRAINTS_FILE" --insecure --progress-bar --output "$localfile" + +pip_install openstack-requirements + +# This is the main purpose of the script: Allow local installation of +# the current repo. It is listed in constraints file and thus any +# install will be constrained and we need to unconstrain it. +edit-constraints "$localfile" -- "$CLIENT_NAME" + +declare -a passthrough_args +while [ $# -gt 0 ] ; do + case "$1" in + # If we have any special os: deps then process them + os:*) + declare -a pkg_spec + IFS=: pkg_spec=($1) + install_from_git "${pkg_spec[1]}" "${pkg_spec[2]}" + ;; + # Otherwise just pass the other deps through to the constrained pip install + *) + passthrough_args+=("$1") + ;; + esac + shift 1 +done + +# If *only* had special args then then isn't any need to run pip. +if [ -n "$passthrough_args" ] ; then + pip_install "${passthrough_args[@]}" +fi diff --git a/{{cookiecutter.repo_name}}/tox.ini b/{{cookiecutter.repo_name}}/tox.ini index d5859af..2b39cac 100644 --- a/{{cookiecutter.repo_name}}/tox.ini +++ b/{{cookiecutter.repo_name}}/tox.ini @@ -6,14 +6,18 @@ skipsdist = True [testenv] usedevelop = True setenv = VIRTUAL_ENV={envdir} + BRANCH_NAME=master + CLIENT_NAME={{cookiecutter.repo_name}} NOSE_WITH_OPENSTACK=1 NOSE_OPENSTACK_COLOR=1 NOSE_OPENSTACK_RED=0.05 NOSE_OPENSTACK_YELLOW=0.025 NOSE_OPENSTACK_SHOW_ELAPSED=1 -install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -U {opts} {packages} +install_command = {toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt + # os:* is handled by tox_install.sh + os:openstack/horizon:horizon commands = python manage.py test {posargs} --settings={{cookiecutter.module_name}}.test.settings [testenv:pep8]