#!/usr/bin/env bash # bin/compile set -eo pipefail env which python 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" export PIP_DOWNLOAD_CACHE indent() { RE="s/^/ /" [ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE" } virtualenv() { python - "$@" < /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 $(bin/pip --version | awk '{print $2}')" pip install --use-mirrors -r requirements.txt | indent # Django support. if [ "$NAME" = "Python/Django" ] && ! [ "$DISABLE_INJECTION" ]; 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