-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-virt-env
45 lines (35 loc) · 1.25 KB
/
start-virt-env
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
#!/bin/bash
REQ_PYTHON_MAJ=3
REQ_PYTHON_MINOR=8
FROM_RUN=""
if [ "$1" == "--from-run" ]; then
FROM_RUN="yes"
fi
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$PWD/.virtualenvs
export PROJECT_HOME=$PWD
RED_COLOR='\033[0;31m'
NO_COLOR='\033[0m'
if [ -f /usr/share/virtualenvwrapper/virtualenvwrapper.sh ]; then
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
elif [-f ~/.local/bin/virtualenvwrapper.sh ]; then
export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
else
echo -e "${RED_COLOR}ERROR${NO_COLOR} cannot not find virtualen. Please install it"
exit 1
fi
if ! workon | grep -q run_env; then
mkvirtualenv -r requirements.txt run_env
fi
workon run_env
alias d=deactivate
if ! python -c "import sys; sys.exit(0) if sys.version_info.major == $REQ_PYTHON_MAJ and sys.version_info.minor >= $REQ_PYTHON_MINOR else sys.exit(1)"; then
>&2 echo -e "${RED_COLOR}ERROR${NO_COLOR} Require pyhon >= ${REQ_PYTHON_MAJ}.${REQ_PYTHON_MINOR} Exit from virtual env"
deactivate
(return 0 2>/dev/null) && return 1
fi
if [ "$FROM_RUN" == "" ]; then
echo "Virtual environment has been started. Use 'deactivate' or 'd' for exit"
fi