-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_environment.sh
executable file
·74 lines (61 loc) · 1.86 KB
/
create_environment.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
#!/bin/bash
# Copyright Bruno Rahle 2014
# MIT License
# This script helps recreate the virtual environment used in a project that
# django-quickstart created.
#
# It should be located in the root of the repository.
# Detect the directory of the source file. Taken from
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
# resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
# if $SOURCE was a relative symlink, we need to resolve it relative to the path
# where the symlink file was located
done
export SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
function execute {
echo "Executing $@..."
$@
if [ $? -eq 0 ]
then
echo "Done!"
echo
else
echo "Failed!!!"
exit 1
fi
}
function confirm {
read -r -p "${1:-Are you sure? [Y/n]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
[nN][oO]|[nN])
false
;;
*)
true
;;
esac
}
if ! confirm "This will create a new virtual environment. Continue [Y/n] ?"
then
exit 0
fi
LOCATION=$(pwd)/virtualenv
read -e -p "Location of the virtualenv? " -i "$LOCATION" LOCATION
# Install the virtualenv
execute mkdir -p $LOCATION
execute virtualenv $LOCATION
cd $LOCATION
source $LOCATION/bin/activate
# Install the requirements
execute pip install -r $SCRIPT_DIR/.environment_settings/requirements.txt
# Create a link to activate the environment in the repository
execute ln -sf $LOCATION/bin/activate $SCRIPT_DIR/activate
echo "You should now be able to source the activate script from the root of your repository - '$SCRIPT_DIR'!"