-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetvenv
executable file
·104 lines (82 loc) · 4 KB
/
setvenv
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
97
98
99
100
101
102
103
104
#!/bin/bash
# this file should be run once per virtualenv to add the emceevirtualenv customizations
echo "running setvenv"
# if you would like to add these customizations automatically whenever you
# run mkvirtualenv, add $WORKON_HOME/setvenv to your global postmkvirtualenv file
# ($WORKON_HOME/postmkvirtualenv)
# WARNING: this script assumes you are already in the project root, so be sure to
# use it accordingly
# pull in variables from config file
source $WORKON_HOME/EmceeVirtualEnv_config
# This mimics the behavior of setvirtualenvproject
# it creates a .project file in the virtualenv that stores
# the current directory as the project root for that virtualenv
echo $(pwd) > $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME
# I'm sure there's a better way to generate files with a bash script,
# but I'm woefully unlearned on that front, so please educate me if you can
# check for an existing virtualenv
if [ -f $MCV_VENV_NAME ]; then
echo "$MCV_VENV_NAME found, would you like to append to it? (y/N)"
read APPEND
if [ "$APPEND" = "y" ]; then
echo "appending to $MCV_VENV_NAME"
echo "" >> $MCV_VENV_NAME
else
echo "cancelling operation"
return
fi
else
echo "making file \"$MCV_VENV_NAME\" to store local environment variables"
echo "#!/bin/bash" >> $MCV_VENV_NAME
echo "# This file is run whenever you activate this virtualenv." >> $MCV_VENV_NAME
echo "# Add environment variables and local aliases here" >> $MCV_VENV_NAME
fi
echo 'echo "running local venv"' >> $MCV_VENV_NAME
echo "" >> $MCV_VENV_NAME
echo "" >> $MCV_VENV_NAME
echo "# ------------------" >> $MCV_VENV_NAME
echo "# EmceeVirtualEnv generated stuff:" >> $MCV_VENV_NAME
echo "" >> $MCV_VENV_NAME
echo "# The following shoud be the full file path to the\
root of your django project - where manage.py goes." >> $MCV_VENV_NAME
# assume the current dir is project root...
echo export DJANGO_PROJECT_ROOT="$(pwd)" >> $MCV_VENV_NAME
# search for a settings file
# this command needs work
# DSM=$(readlink -f "$(find -name settings*)")
# DSM="$(readlink -f "$(find -regex ".*/setting.*[^c]$")")"
DSM=$(find -regex ".*/setting.*[^c]$" | head -1 |\
sed -e 's!^\.\/!!' -e 's!\..*!!' -e 's!\/!\.!g')
if [ "$DSM" ]; then
echo "using \"$DSM\" as settings module, correct this in your $MCV_VENV_NAME if that's not correct"
else
echo "settings file not found, manually add its path to DJANGO_SETTINGS_MODULE in your $MCV_VENV_NAME file"
fi
echo "" >> $MCV_VENV_NAME
echo "# This should be the python dot path to get to your settings module" >> $MCV_VENV_NAME
echo "# If your settings module is in the root of your project, \
it'll be \"settings\"" >> $MCV_VENV_NAME
echo "# Otherwise it'll be something like \"myproject.settings\"" >> $MCV_VENV_NAME
echo export DJANGO_SETTINGS_MODULE="$DSM" >> $MCV_VENV_NAME
# VirtualEnvWrapper provides a command add2virtualenv that adds stuff to
# a .pth file inside site-packages, but this will allow the user to change
# DJANGO_PROJECT_ROOT if needed
echo "" >> $MCV_VENV_NAME
echo "# This is adds the project root to your PYTHONPATH \
so things inside it can be imported" >> $MCV_VENV_NAME
echo export "PYTHONPATH=\$PYTHONPATH:\$DJANGO_PROJECT_ROOT" >> $MCV_VENV_NAME
echo "" >> $MCV_VENV_NAME
echo "" >> $MCV_VENV_NAME
echo "# example secret key setting (please change the key if you use this)" >> $MCV_VENV_NAME
echo "# export DJANGO_SECRET_KEY='1of*b8rert1h^yxfte1kkl3tr#_k+orinrbw(d!p_=l6bd(v#2'" >> $MCV_VENV_NAME
echo "" >> $MCV_VENV_NAME
echo '# You should also use environment variables to turn debug on and off' >> $MCV_VENV_NAME
echo '# rather than changing the code every time.' >> $MCV_VENV_NAME
echo '# export DJANGO_DEBUG="True"' >> $MCV_VENV_NAME
echo "" >> $MCV_VENV_NAME
echo '# You can also use a DJANGO_ENV (or similar) variable to differentiate' >> $MCV_VENV_NAME
echo '# between development, staging, and production settings.' >> $MCV_VENV_NAME
echo '# export DJANGO_ENV="DEV"' >> $MCV_VENV_NAME
# source the new venv
source $WORKON_HOME/postactivate
# source $MCV_VENV_NAME