-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkenv.sh
executable file
·66 lines (52 loc) · 1.54 KB
/
mkenv.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
#!/bin/bash
#
# Run this without options to create a virtual
# environment for the current git branch
#
# Override the default virtual enviornment name through
# the single argument to script:
#
# mkenv.sh <env_name>
#
PROG=${0}
# We need virtualenv from somewhere
virtualenv=`which virtualenv`
if [ ! -x "${virtualenv}" ]; then
echo "location of virtualenv executable is unknown"
exit 1
fi
# Set up env_name either from command line, else current git branch
if [ $# -eq 1 ]; then
env_name=$1
else
env_name=`git rev-parse --abbrev-ref HEAD`
fi
# Normalize env_name, replace '/' with '_'
env_name=${env_name//\//_}
# Our virtual environments are found within <toplevelgit>/env
#cd "$(git rev-parse --show-toplevel)"
export WORKON_HOME=`pwd`/env
# mkvirtualenv, OK if its already there
${virtualenv} --clear env/${env_name}
# activate the virtual environment
source "env/${env_name}/bin/activate"
# Use locally sourced pip configuration
export PIP_CONFIG_FILE=`pwd`/pip.conf
# Install all required packages
pip install -r requirements.txt
# Create local requirements (for example, pylint)
if [ -f requirements_local.txt ]
then
pip install -r requirements_local.txt
fi
# Generate a script that assists in switching environments
cat > myenv_${env_name} <<End-of-message
# *** Autgenerated file, do not commit to remote repository
export WORKON_HOME="${WORKON_HOME}"
source "env/${env_name}/bin/activate"
End-of-message
echo ""
echo "${PROG}: complete, run the following to use '${env_name}' environment:"
echo
echo "source myenv_${env_name}"
exit 0