From 37927ffd9ccf8699a671107a97cd8576a5faac97 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 25 Jun 2015 11:09:58 -0400 Subject: [PATCH] tools/tox-venv: support running other than ./tools/tox-venv this improves tox-venv to: a.) consider ./.tox as the tox dir useful if you run tox-venv from ~/bin and you're in cloud-init dir with .tox there. if no tox.ini and .tox are in this dir, fall back to using the old look ${0%/*}/../.tox b.) support '--list' ie, running tox-venv adds support to tox-venv so you can list environments explicitly c.) outputs the list of available environments with --help a '*' at the end indicates the environment appears presnt. d.) any environment not present will be created with unless '--no-create' e.) 4 spaces instead of 3 for indentation consistency with python Example usage: $ tox-venv docs python --version Python 3.4.3+ Change-Id: I8a3d07c27fc3e4e41421e59ac5f47628a3612b83 --- tools/tox-venv | 80 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 15 deletions(-) diff --git a/tools/tox-venv b/tools/tox-venv index 469e74c1..32a16851 100755 --- a/tools/tox-venv +++ b/tools/tox-venv @@ -1,30 +1,80 @@ #!/bin/sh +# vi: ts=4 expandtab error() { echo "$@" 1>&2; } fail() { [ $# -eq 0 ] || error "$@"; exit 1; } -Usage() { - cat <&2; exit 1; } -[ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; } +Usage() { + local tox_d="$1" tox_ini="$2" + cat <&2; exit 1; } +[ "$1" = "-h" -o "$1" = "--help" ] && { Usage "$tox_d" "$tox_ini"; exit 0; } + +[ -d "$tox_d" ] || fail "$tox_d: not a dir. maybe run 'tox'?" +[ -f "$tox_ini" ] || fail "$tox_ini: did not find tox.ini" + +if [ "$1" = "-l" -o "$1" = "--list" ]; then + list_environments "$tox_d" "$tox_ini" + exit +fi + +nocreate="false" +if [ "$1" = "--no-create" ]; then + nocreate="true" + shift +fi env="$1" shift -tox_d="${0%/*}/../.tox" activate="$tox_d/$env/bin/activate" -[ -d "$tox_d" ] || fail "$tox_d: not a dir. maybe run 'tox'?" if [ ! -f "$activate" ]; then - error "$env: not a valid tox environment?" - error "try one of:" - ( cd "$tox_d" && - for d in *; do [ -f "$d/bin/activate" ] && error " $d"; done ) - fail + if $nocreate; then + fail "tox env '$env' did not exist, and no-create specified" + elif list_environments "$tox_d" "$tox_ini" | grep -q " $env$"; then + error "attempting to create $env:" + error " tox -c $tox_ini --recreate --notest -e $env" + tox -c "$tox_ini" --recreate --notest -e "$env" || + fail "failed creation of env $env" + else + error "$env: not a valid tox environment?" + error "found tox_d=$tox_d" + error "try one of:" + list_environments "$tox_d" "$tox_ini" 1>&2 + fail + fi fi . "$activate"