blob: c23a02d1bc4f643096a092656ace1b6990cdae6f (
plain)
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
40
41
42
43
44
45
46
47
48
|
#!/bin/sh
venv() {
if ! command -V "venv_$1" | grep -q " function "
then
cat <<EOF
Usage:
venv on
venv off
Manage the python venv for a given project or directory.
Commands:
on Enable the venv for \$PWD
off Deactivate the current venv
EOF
return 1
fi
"venv_$1"
}
venv_on() {
export PYTHON_VENV_DIR="$PWD/.venv"
export VIRTUAL_ENV_DISABLE_PROMPT=1
if [ ! -d "$PYTHON_VENV_DIR" ]
then
printf "Initializing venv directory at %s\n" "$PYTHON_VENV_DIR"
python3 -m venv "$PYTHON_VENV_DIR"
fi
. "$PYTHON_VENV_DIR/bin/activate"
}
venv_off() {
if [ -z "$PYTHON_VENV_DIR" ]
then
printf "No venv active?\n"
return 1
fi
deactivate
unset PYTHON_VENV_DIR
unset VIRTUAL_ENV_DISABLE_PROMPT
}
|