~miconoco/venv

ref: 302ab363176492b0875c635ef4ddbdc2c8301ddb venv/venv -rwxr-xr-x 820 bytes
302ab363Christoph Polcin add venv 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 <<EOF >&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