#!/bin/bash

# thanks Carl
# tweaks by Mat

set -e

usage () {
  echo "usage: $(basename "$0") venv-dir python-script [args...]" >&2
  echo
  echo "Run python-script under venv environment."
  exit $1
}

if [[ -z $1 ]]; then
    usage 2
elif [[ $1 = -h* || $1 = --h* ]]; then
    usage 0
fi

if [[ ! -r $1/bin/activate ]]; then
    echo >&2 "virtualenv under $1 not found or not usable"
    exit 1
fi

. "$1"/bin/activate
shift
exec python "$@"

