diff options
| author | Silvio Rhatto <rhatto@riseup.net> | 2025-02-14 13:27:28 -0300 | 
|---|---|---|
| committer | Silvio Rhatto <rhatto@riseup.net> | 2025-02-14 13:27:28 -0300 | 
| commit | caeacfb3af668033f7ee8d9206cbe604efc9aacb (patch) | |
| tree | a35b570346410721c2e87aa175e2a6cc07a74593 | |
| parent | 0220c9924c6fb633e7cd55be548a1604fdf4f63c (diff) | |
| download | scripts-master.tar.gz scripts-master.tar.bz2  | |
| -rwxr-xr-x | run-on-venv | 51 | 
1 files changed, 51 insertions, 0 deletions
diff --git a/run-on-venv b/run-on-venv new file mode 100755 index 0000000..e6fdf7e --- /dev/null +++ b/run-on-venv @@ -0,0 +1,51 @@ +#!/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 +$*  | 
