From 302ab363176492b0875c635ef4ddbdc2c8301ddb Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Thu, 26 Nov 2020 15:50:19 +0100 Subject: [PATCH] add venv --- venv | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 venv diff --git a/venv b/venv new file mode 100755 index 0000000..541cdcd --- /dev/null +++ b/venv @@ -0,0 +1,39 @@ +#!/bin/sh + +set -eu + +app="${0##*.}" +VENV=${VENV:-~/.venv} +PY=${PY:-python3} + +if [ "$app" = "$0" ]; then + # TODO URL from ARGS to support git ... + [ $# = 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] && cat <&2 && exit 1 +usage: $(basename "$0") APP -> $(basename "$0").APP [freeze] + +ENV + VENV=${VENV} + PY=${PY} +EOF + ln -srf "${0}" "${0}.${1}" + app="$1" +fi + +aenv="$VENV/$app" +req="$VENV/$app.requirements.txt" + +# TODO destroy python version if changed +[ ! -d "$aenv" ] && PY -m venv "$aenv" + +[ $# -gt 0 ] && [ "$1" = "freeze" ] && "$aenv/bin/pip" freeze | tee "$req" && exit 0 + +"$aenv/bin/python" -m pip install --upgrade pip + +if [ -f "$req" ]; then + "$aenv/bin/pip" install -r "$req" +else + "$aenv/bin/pip" install --upgrade "$app" +fi + +# TODO symlink all to $venv/bin or ~/.local/bin +ln -srf "$aenv/bin/$app" ~/bin -- 2.34.2