forked from qmk/qmk_web_stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_virtualenv
executable file
·89 lines (77 loc) · 2.44 KB
/
setup_virtualenv
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
#!/bin/sh
#
# Script to setup a virtualenv. Set PYTHON_VERSION to pick a particular
# version of python. Defaults to Python 3.
# Determine our python version
if [ -z "$PYTHON_VERSION" ]; then
if python3 --version > /dev/null; then
PYTHON_VERSION=3
elif python3.5 --version > /dev/null; then
PYTHON_VERSION=3.5
elif python3.4 --version > /dev/null; then
PYTHON_VERSION=3.4
elif python3.3 --version > /dev/null; then
PYTHON_VERSION=3.3
elif python3.2 --version > /dev/null; then
PYTHON_VERSION=3.2
elif python3.1 --version > /dev/null; then
PYTHON_VERSION=3.1
elif python3.0 --version > /dev/null; then
PYTHON_VERSION=3.0
else
echo 'Can not determine python version. Please set PYTHON_VERSION!'
exit 1
fi
fi
# Do some sanity checking
if ! [ -f docker-compose.yml ]; then
echo 'You must run this in the top level of qmk_web_stack!'
exit 1
elif [ -d .qmk_compiler_api-$PYTHON_VERSION -a "$1" != "-f" ]; then
echo 'Not replacing existing virtualenv. Use -f to override.'
exit 1
elif ! virtualenv --version 2>&1 > /dev/null; then
echo "You must install virtualenv first!"
echo
echo "Try: sudo easy_install virtualenv"
exit 1
elif [ -n "$VIRTUAL_ENV" ]; then
echo "You must 'deactivate' your current virtualenv before running this!"
exit 1
fi
# If necessary, wipe away the old virtualenv
if [ -d venv ]; then
while true; do
echo "About to remove the existing virtualenv. OK to proceed?"
read answer
case $answer in
yes|YES)
rm -rf venv
break
;;
no|NO)
echo "Can't proceed while existing virtualenv is in the way."
exit 1
;;
*)
echo 'Please answer "yes" or "no".'
;;
esac
done
fi
# Create the new virtualenv
virtualenv -p python$PYTHON_VERSION venv || exit
# Setup the environment
source venv/activate-$PYTHON_VERSION || exit
for dir in qmk_api qmk_api_tasks qmk_bot qmk_compiler; do
pip install -r $dir/requirements.txt || exit
done
if [ -d ./qmk_compiler ]; then
pip install --editable qmk_compiler
fi
cat << EOF
===============================================================================
Congratulations! VirtualEnv setup was completed successfully!
To get started activate your virtualenv:
$ source $PWD/activate-$PYTHON_VERSION
EOF