#!/usr/bin/env bash # # Helper script to run a command inside a virtualenv # # This is too simple, and you might want to use # virtualenvwrapper instead: # # https://tracker.debian.org/pkg/virtualenvwrapper # https://virtualenvwrapper.readthedocs.io/en/latest/ # https://doughellmann.com/projects/virtualenvwrapper/ # # Or pipx: # # https://pipx.pypa.io/stable/ # https://tracker.debian.org/pkg/python-pipx # # Parameters BASENAME="`basename $0`" COMMAND="$1" VENV="${VENV:$HOME/.virtualenvs/$COMMAND}" # Check for a test if [ -z "$COMMAND" ]; then echo "usage: $BASENAME <command> [args]" exit 1 fi # Deactivate any active virtualenv deactivate &> /dev/null # Create and activate a virtualenv as needed if [ ! -e "$VENV" ]; then mkdir -p `dirname $VENV` python -m venv $VENV . $VENV/bin/activate pip install --upgrade pip pip install $COMMAND else # Check for a virtualenv if [ ! -e "$VENV/bin/activate" ]; then echo "$BASENAME: missing or invalid virtualenv" exit 1 fi # Activate the virtualenv . $VENV/bin/activate fi # Run $*