From caeacfb3af668033f7ee8d9206cbe604efc9aacb Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 14 Feb 2025 13:27:28 -0300 Subject: Feat: adds run-on-venv --- run-on-venv | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 run-on-venv (limited to 'run-on-venv') 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 [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 +$* -- cgit v1.2.3