Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 21 additions & 68 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ PROFILE_PATH="$BUILD_DIR/.profile.d/python.sh"
# Python version. This will be used in the future to specify custom Pythons.
DEFAULT_PYTHON_VERSION="python-2.7.8"
PYTHON_EXE="$APP_PYTHON_HOME_DIR/bin/python"
PIP_VERSION="1.3.1"
DISTRIBUTE_VERSION="0.6.36"

# Setup bpwatch
export PATH=$PATH:$ROOT_DIR/vendor/bpwatch
Expand Down Expand Up @@ -71,6 +69,7 @@ BUILDPACK_PYTHON_HOME=$BUILD_DIR/$PAASPROVIDER_DIR/python
export PATH=$APP_PYTHON_HOME_DIR/bin:$PATH
export PYTHONUNBUFFERED=1
export LANG=en_US.UTF-8
hash -r

# Switch to the repo's context.
cd $BUILD_DIR
Expand Down Expand Up @@ -108,95 +107,49 @@ bpwatch start restore_cache
done
bpwatch stop restore_cache

set +e
# Create set-aside `$PAASPROVIDER_DIR` folder.
mkdir $PAASPROVIDER_DIR &> /dev/null
set -e
mkdir $PAASPROVIDER_DIR &> /dev/null || true

mkdir -p $(dirname $PROFILE_PATH)

set +e
PYTHON_VERSION=$(cat runtime.txt)

# Install Python.
if [ -f $PAASPROVIDER_DIR/python-version ]; then
if [ ! $(cat $PAASPROVIDER_DIR/python-version) = $PYTHON_VERSION ]; then
bpwatch start uninstall_python
puts-step "Found $(cat $PAASPROVIDER_DIR/python-version), removing."
rm -fr $PAASPROVIDER_DIR/python
bpwatch stop uninstall_python
else
SKIP_INSTALL=1
fi
fi

if [[ $(cat $PAASPROVIDER_DIR/python-version 2>/dev/null) == "$PYTHON_VERSION" ]]; then
puts-step "Using Python runtime ($PYTHON_VERSION)"
else
puts-step "Preparing Python runtime ($PYTHON_VERSION)"
rm -fr "$PAASPROVIDER_DIR/python" 2>/dev/null

if [ ! "$SKIP_INSTALL" ]; then
bpwatch start install_python
puts-step "Preparing Python runtime ($PYTHON_VERSION)"
curl "$ARTIFACT_SOURCE_URL/$PYTHON_VERSION.tar.bz2" -s -L | tar jx &> /dev/null
if [[ $? != 0 ]] ; then
puts-warn "Requested runtime ($PYTHON_VERSION) was not found."
puts-warn "Aborting."
exit 1
fi
mv python $PAASPROVIDER_DIR/python
bpwatch stop install_python
if ! curl -sSL "$ARTIFACT_SOURCE_URL/$PYTHON_VERSION.tar.bz2" | tar -jxC "$PAASPROVIDER_DIR"; then
puts-warn "Requested runtime ($PYTHON_VERSION) was not found."
puts-warn "Aborting."
exit 1
fi

# Record for future reference.
echo $PYTHON_VERSION > $PAASPROVIDER_DIR/python-version
FRESH_PYTHON=true

hash -r
else
puts-step "Using Python runtime ($PYTHON_VERSION)"
hash python
fi

# If Pip isn't up to date:
if [ "$FRESH_PYTHON" ] || [[ ! $(pip --version) == *$PIP_VERSION* ]]; then
WORKING_DIR=$(pwd)

bpwatch start prepare_environment

bpwatch start install_distribute
# Prepare it for the real world
puts-step "Installing Distribute ($DISTRIBUTE_VERSION)"
cd $ROOT_DIR/vendor/distribute-$DISTRIBUTE_VERSION/
python setup.py install &> /dev/null
cd $WORKING_DIR
bpwatch stop install_distribute

bpwatch start install_pip
puts-step "Installing Pip ($PIP_VERSION)"
cd $ROOT_DIR/vendor/pip-$PIP_VERSION/
python setup.py install &> /dev/null
cd $WORKING_DIR

bpwatch stop install_pip
bpwatch stop prepare_environment
local_pip="$BUILDPACK_PYTHON_HOME/bin/pip"
if [[ ! -a $local_pip ]]; then
curl -sSL "https://bootstrap.pypa.io/get-pip.py" | python | indent
fi

set -e
hash -r
"$local_pip" install --disable-pip-version-check -U setuptools pip | cleanup | indent

# Install Mercurial if it appears to be required.
if (grep -Fiq "hg+" requirements.txt) then
bpwatch start mercurial_install
$APP_PYTHON_HOME_DIR/bin/pip install --use-mirrors mercurial | cleanup | indent
"$local_pip" install --use-mirrors mercurial | cleanup | indent
bpwatch stop mercurial_install
fi

# Install dependencies with Pip.
puts-step "Installing dependencies using Pip ($PIP_VERSION)"


[ ! "$FRESH_PYTHON" ] && bpwatch start pip_install
[ "$FRESH_PYTHON" ] && bpwatch start pip_install_first

$APP_PYTHON_HOME_DIR/bin/pip install --use-mirrors -r requirements.txt --exists-action=w --src=./$PAASPROVIDER_DIR/src | indent
puts-step "Installing dependencies using ($($local_pip --version))"

[ ! "$FRESH_PYTHON" ] && bpwatch stop pip_install
[ "$FRESH_PYTHON" ] && bpwatch stop pip_install_first
"$local_pip" install -r requirements.txt --src=./$PAASPROVIDER_DIR/src | indent

# Django collectstatic support.
bpwatch start collectstatic
Expand All @@ -212,7 +165,7 @@ set-env PYTHONHOME $APP_PYTHON_HOME_DIR
set-env PATH '$PYTHONHOME/bin:$PATH'
set-default-env LANG en_US.UTF-8
set-default-env PYTHONHASHSEED random
set-default-env PYTHONPATH $APP_DIR/
set-default-env PYTHONPATH $APP_DIR


# Experimental post_compile hook.
Expand Down
Loading