forked from heroku/heroku-buildpack-python
-
Notifications
You must be signed in to change notification settings - Fork 38
/
compile
executable file
·112 lines (88 loc) · 2.8 KB
/
compile
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
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
set -eo pipefail
# Prepend proper path for virtualenv hackery. Will be deprecated soon.
export PATH=:/usr/local/bin:$PATH
BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
ROOT_DIR=$(dirname $BIN_DIR)
BUILD_DIR=$1
CACHE_DIR=$2
NAME=$($BIN_DIR/detect $BUILD_DIR)
PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-$CACHE_DIR/pip_downloads}
VIRTUALENV_DIRS="bin include lib"
VENDORED_MEMCACHED="http://cl.ly/0a191R3K160t1w1P0N25/vendor-libmemcached.tar.gz"
unset GIT_DIR
export PIP_DOWNLOAD_CACHE
indent() {
RE="s/^/ /"
[ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE"
}
function virtualenv (){
python "$ROOT_DIR/src/virtualenv-1.7/virtualenv.py" "$@"
}
cd $BUILD_DIR
# Reject a non-packaged Django app.
if [ "$NAME" = "Python" ]; then
[ -f manage.py ] && [ -f settings.py ] && { echo " ! Django app must be in a package subdirectory"; exit 1; }
fi
# Warn a checked-in virtualenv.
if [ -d "lib" ] || [ -d "bin" ]; then
echo " ! You have a virtualenv checked in. You should ignore the appropriate paths in your repo. See http://devcenter.heroku.com/articles/gitignore for more info.";
fi
# Reject a conflicting checked-in virtualenv.
if [ -f "lib/python2.7" ]; then
echo " ! Checked-in virtualenv conflict."
exit 1;
fi
# Copy artifacts out of cache if exists.
mkdir -p $CACHE_DIR
for dir in $VIRTUALENV_DIRS; do
cp -R $CACHE_DIR/$dir . &> /dev/null || true
done
# Create virtualenv. Rebuild if corrupt.
set +e
echo "-----> Preparing virtualenv version $(virtualenv --version)"
# Try to create the virtualenv.
OUT=$(virtualenv --distribute --never-download --prompt=venv . 2>&1)
# If there's an error, purge and recreate.
[ $? -ne 0 ] && {
echo " ! Virtualenv corrupt, rebuilding."
for dir in $VIRTUALENV_DIRS; do
rm -fr $dir &> /dev/null || true
done
OUT=$(virtualenv --distribute --never-download --prompt=venv . )
}
echo "$OUT" | indent
set -e
# Create set-aside .heroku folder.
mkdir -p .heroku
# Pylibmc support.
source $BIN_DIR/steps/pylibmc
# Activate the virtualenv.
echo "-----> Activating virtualenv"
source bin/activate
# Install mercurial, if needed.
if (grep -Fiq "hg+" requirements.txt) then
pip install --use-mirrors mercurial | indent
fi
# Install dependencies.
echo "-----> Installing dependencies using pip version $(pip --version | awk '{print $2}')"
pip install --use-mirrors -r requirements.txt --src ./.heroku/src | indent
# Django support.
if [ "$NAME" = "Python/Django" ]; then
source $BIN_DIR/steps/django
fi
# Make virtualenv relocatable.
set +e
OUT=$(virtualenv --relocatable .)
[ $? -ne 0 ] && {
echo " ! Error making virtualenv relocatable"
echo "$OUT" | indent
exit 1
}
set -e
# Store new artifacts in cache.
for dir in $VIRTUALENV_DIRS; do
rm -rf $CACHE_DIR/$dir
cp -R $dir $CACHE_DIR/
done