Merge "tools/tox-venv: support running other than ./tools/tox-venv"
This commit is contained in:
commit
d072623527
@ -1,30 +1,80 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
# vi: ts=4 expandtab
|
||||||
|
|
||||||
error() { echo "$@" 1>&2; }
|
error() { echo "$@" 1>&2; }
|
||||||
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
|
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
|
||||||
Usage() {
|
list_environments() {
|
||||||
cat <<EOF
|
local tox_d="$1" tox_ini="$2" prefix=" "
|
||||||
Usage: ${0##*/} tox-environment [command [args]]
|
envs=$(tox -c "$tox_ini" --listenvs) || return 1
|
||||||
run command with provided arguments in the provided tox environment
|
(
|
||||||
command defaults to \${SHELL:-/bin/sh}.
|
cd "$tox_d" &&
|
||||||
EOF
|
for d in ${envs}; do
|
||||||
|
[ -f "$d/bin/activate" ] && s="*" || s=""
|
||||||
|
echo "${prefix}$d$s";
|
||||||
|
done
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $# -eq 0 ] && { Usage 1>&2; exit 1; }
|
Usage() {
|
||||||
[ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
|
local tox_d="$1" tox_ini="$2"
|
||||||
|
cat <<EOF
|
||||||
|
Usage: ${0##*/} [--no-create] tox-environment [command [args]]
|
||||||
|
run command with provided arguments in the provided tox environment
|
||||||
|
command defaults to \${SHELL:-/bin/sh}.
|
||||||
|
|
||||||
|
run with '--list' to show available environments
|
||||||
|
EOF
|
||||||
|
if [ -d "$tox_d" -a -f "$tox_ini" ]; then
|
||||||
|
echo
|
||||||
|
echo "existing environments in $tox_d"
|
||||||
|
list_environments "$tox_d" "$tox_ini"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -f tox.ini -a -d .tox ]; then
|
||||||
|
tox_d="./.tox"
|
||||||
|
tox_ini="$PWD/tox.ini"
|
||||||
|
else
|
||||||
|
tox_d="${0%/*}/../.tox"
|
||||||
|
tox_ini="${0%/*}/../tox.ini"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ $# -eq 0 ] && { Usage "$tox_d" "$tox_ini" 1>&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"
|
env="$1"
|
||||||
shift
|
shift
|
||||||
tox_d="${0%/*}/../.tox"
|
|
||||||
activate="$tox_d/$env/bin/activate"
|
activate="$tox_d/$env/bin/activate"
|
||||||
|
|
||||||
[ -d "$tox_d" ] || fail "$tox_d: not a dir. maybe run 'tox'?"
|
|
||||||
if [ ! -f "$activate" ]; then
|
if [ ! -f "$activate" ]; then
|
||||||
error "$env: not a valid tox environment?"
|
if $nocreate; then
|
||||||
error "try one of:"
|
fail "tox env '$env' did not exist, and no-create specified"
|
||||||
( cd "$tox_d" &&
|
elif list_environments "$tox_d" "$tox_ini" | grep -q " $env$"; then
|
||||||
for d in *; do [ -f "$d/bin/activate" ] && error " $d"; done )
|
error "attempting to create $env:"
|
||||||
fail
|
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
|
fi
|
||||||
. "$activate"
|
. "$activate"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user