-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvenv.sh
executable file
·96 lines (73 loc) · 2.37 KB
/
venv.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
set -e
script_dir=${0%/*}
[ "${script_dir}" != "$0" ] || script_dir=.
script_name=${0##*/}
venv_dir="${script_dir}/venv"
python="python3" # non-venv and venv interpreter name
pip="pip --require-virtualenv" # used only in venv
package="curldl"
error()
{
echo "$@" 1>&2
exit 1
}
activate_venv()
{
if [ -d "${venv_dir}"/bin ]; then
. "${venv_dir}"/bin/activate
else
. "${venv_dir}"/Scripts/activate
fi
}
if [ $# = 0 ]; then
error "${script_name} install-venv | upgrade-venv | downgrade-venv | <command> <args>..."
fi
if [ -e "${venv_dir}" ]; then
activate_venv
elif [ "$1" != "install-venv" ]; then
error "virtualenv environment not found at ${venv_dir}"
fi
export PYTHONDONTWRITEBYTECODE=1
export PYTHONDEVMODE=1
# export PYTHONTRACEMALLOC=20
export PYTHONIOENCODING=utf-8
# export PYTHONWARNDEFAULTENCODING=1
if [ "$1" = "install-venv" ]; then
echo "Installing virtualenv..."
if [ -e "${venv_dir}" ] || [ -n "${VIRTUAL_ENV}" ]; then
error "virtualenv is enabled or venv directory present"
fi
if ! ${python} -m ensurepip --version 1>/dev/null 2>&1; then
error "ensurepip is not available, run: sudo apt install python3-venv"
fi
python_platform=$(${python} -c 'import sys; print(sys.platform)')
if [ "${python_platform}" != "win32" ] && ! curl-config --version 1>/dev/null 2>&1; then
# NOTE: curl-config is not required if PyPI has native PycURL builds
error "curl-config is not available, run: sudo apt install libcurl4-openssl-dev"
fi
python_version=$(${python} -c 'import sys; print(sys.version.split()[0])')
${python} -m venv --symlinks --prompt "venv/${python_version}" "${venv_dir}"
activate_venv
# venv --upgrade-deps is available from Python 3.9.0
${python} -m pip --require-virtualenv install -U pip setuptools
${pip} install --use-pep517 "${script_dir}[test,dev,doc]"
${pip} uninstall -y ${package}
${pip} install -e "${script_dir}"
${pip} check
exit
fi
if [ "$1" = "downgrade-venv" ]; then
${pip} install --use-pep517 --force-reinstall "${script_dir}[minimal]"
${pip} uninstall -y ${package}
${pip} install -e "${script_dir}"
${pip} check
exit
fi
if [ "$1" = "upgrade-venv" ]; then
echo "Upgrading virtualenv..."
pip-review --require-virtualenv --auto
${pip} check
exit
fi
exec "$@"