diff --git a/bin/compile b/bin/compile index 37c30efca150595acc1f459c69fc5aee817cb312..c7f083799ca77a14af7f77dad70fff92667861cc 100755 --- a/bin/compile +++ b/bin/compile @@ -159,7 +159,7 @@ pip install --use-mirrors -r requirements.txt --exists-action=w --src=./.heroku/ # See [`bin/steps/django`](django.html). if [ "$NAME" = "Python/Django" ]; then - source $BIN_DIR/steps/django/init + source $BIN_DIR/steps/django fi # Make Virtualenv's paths relative for portability. diff --git a/bin/detect b/bin/detect index 588e15ed12dcc31e0bcf38078d63bb33ed910a59..ccfbff9e27e2a84dc223c0d5e5c2e3f8a3d80b56 100755 --- a/bin/detect +++ b/bin/detect @@ -19,46 +19,11 @@ if [ ! -f $BUILD_DIR/requirements.txt ] && [ ! -f $BUILD_DIR/setup.py ]; then exit 1 fi -# If only `setup.py`, assume that the app is not Django. -if [ ! -f $BUILD_DIR/requirements.txt ]; then - echo Python - exit 0 -fi - -# `Python/Django` if `**/settings.py` is present and `django` exists in -# `requirements.txt`. +# `Python/Django` if `**/settings.py` is present. # # Otherwise, `Python`. -array="" -list_requirements() { -IFS_BAK=$IFS -IFS=" -" - requirement_file=$1 - reqs=$(cat $requirement_file) - for req in $reqs; do - if [[ $req == -r* ]]; then - new_req=$(echo $req | cut -d" " -f2) - if [[ $new_req == $1 ]]; then - continue - fi - directory=$(dirname $requirement_file) - if [[ ! $array == *$directory/$new_req* ]]; then - list_requirements "$directory/$new_req" - fi - array="$array $directory/$new_req" - else - echo $req; - fi - - done -IFS=$IFS_BAK -IFS_BAK= -} - - -SETTINGS_FILE=$(find $BUILD_DIR/. -maxdepth 2 -type f -name 'settings.py' | head -1) +SETTINGS_FILE=$(find $BUILD_DIR/. -maxdepth 3 -type f -name 'settings.py' | head -1) -[ -n "$SETTINGS_FILE" ] && ( list_requirements $BUILD_DIR/requirements.txt | grep -Fiq "django" ) && echo Python/Django || echo Python +[ -n "$SETTINGS_FILE" ] && echo Python/Django || echo Python diff --git a/bin/steps/django b/bin/steps/django new file mode 100644 index 0000000000000000000000000000000000000000..b144212e15569b2356f363ba90d82761de01c7d8 --- /dev/null +++ b/bin/steps/django @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Syntax sugar. +indent() { + RE="s/^/ /" + [ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE" +} + +SETTINGS_FILE=$(find . -maxdepth 3 -type f -name 'settings.py' | head -1) +PROJECT=$(dirname $SETTINGS_FILE) +MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' | head -1) +MANAGE_FILE=${MANAGE_FILE:2} + + +if [ ! "$DISABLE_COLLECTSTATIC" ]; then + set +e + + # Check if collectstatic is configured properly. + python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null && RUN_COLLECTSTATIC=true + + # Compile assets if collectstatic appears to be kosher. + if [ "$RUN_COLLECTSTATIC" ]; then + + echo "-----> Collecting static files" + python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent + + [ $? -ne 0 ] && { + echo " ! Error running manage.py collectstatic. More info:" + echo " http://devcenter.heroku.com/articles/django-assets" + } + fi + + echo + + +fi + diff --git a/bin/steps/django/collectstatic b/bin/steps/django/collectstatic deleted file mode 100755 index 44346e2c708b3f3704bfca441db73ae1980da513..0000000000000000000000000000000000000000 --- a/bin/steps/django/collectstatic +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -set +e - -# Syntax sugar. -indent() { - RE="s/^/ /" - [ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE" -} - - -# Check if collectstatic is configured properly. -python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null && RUN_COLLECTSTATIC=true - -# Compile assets if collectstatic appears to be kosher. -if [ "$RUN_COLLECTSTATIC" ]; then - - echo "-----> Collecting static files" - python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent - - [ $? -ne 0 ] && { - echo " ! Error running manage.py collectstatic. More info:" - echo " http://devcenter.heroku.com/articles/django-assets" - } -fi - -echo - diff --git a/bin/steps/django/init b/bin/steps/django/init deleted file mode 100755 index bb12f55455eb011519bc3f24fe095d16ef34e565..0000000000000000000000000000000000000000 --- a/bin/steps/django/init +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -SETTINGS_FILE=$(find . -maxdepth 3 -type f -name 'settings.py' | head -1) -PROJECT=$(dirname $SETTINGS_FILE) -MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' | head -1) -MANAGE_FILE=${MANAGE_FILE:2} - -if [ "$FRESH_APP" ]; then - # Legacy Django injection for existing applications. - touch .heroku/injection_disabled -fi - -# Disable injection for new applications. -if [ -f .heroku/injection_disabled ]; then - DISABLE_INJECTION=1 -fi - -if [ -f .heroku/collectstatic_disabled ]; then - DISABLE_COLLECTSTATIC=1 -fi - -export SETTINGS_FILE MANAGE_FILE PROJECT DISABLE_INJECTION - -if [ ! "$DISABLE_INJECTION" ]; then - # Legacy Django injection for existing applications. - source $BIN_DIR/steps/django/injection -fi - -if [ ! "$DISABLE_COLLECTSTATIC" ]; then - source $BIN_DIR/steps/django/collectstatic -fi - diff --git a/bin/steps/django/injection b/bin/steps/django/injection deleted file mode 100755 index 5479609951bac2dafa86bc4cecb5c20b10903e6d..0000000000000000000000000000000000000000 --- a/bin/steps/django/injection +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -# This script serves as the Django injection build step of the -# [**Python Buildpack**](https://github.com/heroku/heroku-buildpack-python) -# compiler. -# -# A [buildpack](http://devcenter.heroku.com/articles/buildpacks) is an -# adapter between a Python application and Heroku's runtime. -# -# This script is invoked by [`bin/compile`](/). - -# ## Sanity Checks -# - -# Syntax sugar. -indent() { - RE="s/^/ /" - [ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE" -} - -echo "-----> Injecting legacy Django settings..." -echo " ! WARNING: Settings injection will be fully deprecated on January 1, 2013. More info:" -echo " ! https://devcenter.heroku.com/articles/django-injection " - - -echo "-----> Installing dj-database-url..." -pip install --use-mirrors 'dj-database-url>=0.2.0' | indent - -SETTINGS_FILE=$(find . -maxdepth 2 -type f -name 'settings.py' | head -1) -PROJECT=$(dirname $SETTINGS_FILE) - -echo "Injecting code into $SETTINGS_FILE to read from DATABASE_URL" | indent - -cat >>$SETTINGS_FILE <<EOF - -import dj_database_url - -if 'DATABASES' not in locals(): - DATABASES = {} - -if not 'default' in DATABASES: - DATABASES['default'] = {} - -DATABASES['default'].update(dj_database_url.config(default='postgres://')) - -EOF -