2
# https://gist.github.com/smoser/2d4100a6a5d230ca937f
6
error() { echo "$@" 1>&2; }
7
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
9
# read 'tox --showconfig'. return list of
11
local key="" equal="" val="" curenv="" out=""
12
while read key equal val; do
16
curenv=${curenv%%"]"*};
19
if [ "${key#*=}" != "$key" ]; then
20
# older tox shows key=value or key= value
21
# newer tox shows: key = value
25
[ "$key" = "envdir" ] || continue
26
out="${out:+${out}${CR}}${curenv}:$val"
32
local tox_ini="$1" out="" envs=""
33
if [ "$tox_ini" = "${CACHED_ENVS_INI}" ]; then
37
out=$(tox -c "$tox_ini" --showconfig) || return 1
38
envs=$(echo "$out" | get_env_dirs) || return 1
40
CACHED_ENVS_INI="$tox_ini"
45
local tox_ini="$1" prefix=" " out="" envs="" oifs="$IFS"
46
load_config "$tox_ini" || return 1
52
[ -f "$dir/bin/activate" ] && s="*" || s=""
53
echo "${prefix}$env$s";
59
local tox_ini="$1" env="$2" oifs="$IFS" t="" d="" envs=""
60
if [ "${TOX_VENV_SHORTCUT:-1}" != "0" ]; then
61
local stox_d="${tox_ini%/*}/.tox/${env}"
62
if [ -e "${stox_d}/bin/activate" ]; then
67
load_config "$tox_ini" && envs="$_RET" || return 1
70
[ "$env" = "${t%%:*}" ] && d="${t#*:}" && break
73
[ -n "$d" ] || return 1
80
Usage: ${0##*/} [--no-create] tox-environment [command [args]]
81
run command with provided arguments in the provided tox environment
82
command defaults to \${SHELL:-/bin/sh}.
84
run with '--list' to show available environments
86
if [ -f "$tox_ini" ]; then
88
[ "${tox_ini}" -ef "$PWD/tox.ini" ] && oini="./tox.ini"
90
echo "environments in $oini"
91
list_environments "$tox_ini"
95
if [ -f tox.ini -a -d .tox ]; then
96
tox_ini="$PWD/tox.ini"
98
tox_ini="${0%/*}/../tox.ini"
101
[ $# -eq 0 ] && { Usage "$tox_ini" 1>&2; exit 1; }
102
[ "$1" = "-h" -o "$1" = "--help" ] && { Usage "$tox_ini"; exit 0; }
104
[ -f "$tox_ini" ] || fail "$tox_ini: did not find tox.ini"
106
if [ "$1" = "-l" -o "$1" = "--list" ]; then
107
list_environments "$tox_ini"
112
if [ "$1" = "--no-create" ]; then
119
get_env_dir "$tox_ini" "$env" && activate="$_RET/bin/activate" || activate=""
121
if [ -z "$activate" -o ! -f "$activate" ]; then
123
fail "tox env '$env' did not exist, and no-create specified"
124
elif [ -n "$activate" ]; then
125
error "attempting to create $env:"
126
error " tox -c $tox_ini --recreate --notest -e $env"
127
tox -c "$tox_ini" --recreate --notest -e "$env" ||
128
fail "failed creation of env $env"
130
error "$env: not a valid tox environment?"
131
error "found tox_ini=$tox_ini"
133
list_environments "$tox_ini" 1>&2
139
[ "$#" -gt 0 ] || set -- ${SHELL:-/bin/bash}
140
debian_chroot="tox:$env" exec "$@"