From 3e480e9aeaca62b943c42e716856ae5e32d73794 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Dec 2012 17:34:04 -0500 Subject: [PATCH 1/7] purge old virtualenvs --- bin/compile | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/bin/compile b/bin/compile index 0014ebc..5b71655 100755 --- a/bin/compile +++ b/bin/compile @@ -49,11 +49,9 @@ CACHED_DIRS=".heroku" PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-$CACHE_DIR/pip_downloads} # Static configurations for virtualenv caches. -LEGACY_VIRTUALENV_LOC="." MODERN_VIRTUALENV_LOC=".heroku/venv" -LEGACY_VIRTUALENV_DIRS="bin include lib" LEGACY_VIRTUALENV_TRIGGER="lib/python2.7" -PROFILE_PATH="$1/.profile.d/python.sh" +PROFILE_PATH="$BUILD_DIR/.profile.d/python.sh" # Python version. This will be used in the future to specify custom Pythons. @@ -66,6 +64,7 @@ unset GIT_DIR PYTHONHOME PYTHONPATH LD_LIBRARY_PATH LIBRARY_PATH # We'll need to send these statics to other scripts we `source`. export PIP_DOWNLOAD_CACHE BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH +# Syntax sugar. source $BIN_DIR/utils # ## Build Time @@ -96,24 +95,8 @@ mkdir -p $CACHE_DIR VIRTUALENV_LOC=$MODERN_VIRTUALENV_LOC VIRTUALENV_DIRS=$MODERN_VIRTUALENV_LOC -# Support "old-style" virtualenvs. -if [ -d $CACHE_DIR/$LEGACY_VIRTUALENV_TRIGGER ]; then - LEGACY_VIRTUALENV=true - VIRTUALENV_LOC=$LEGACY_VIRTUALENV_LOC - VIRTUALENV_DIRS=$LEGACY_VIRTUALENV_DIRS - CACHED_DIRS=$LEGACY_VIRTUALENV_DIRS - - # Warn for a checked-in virtualenv. - if [ -d "lib" ] || [ -d "bin" ]; then - puts-warn "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 - puts-warn "Checked-in virtualenv conflict." - exit 1; - fi -fi +# Purge "old-style" virtualenvs. +[ -d $CACHE_DIR/$LEGACY_VIRTUALENV_TRIGGER ] && rm -fr $CACHE_DIR/* # Restore old artifacts from the cache. for dir in $CACHED_DIRS; do @@ -206,16 +189,15 @@ for dir in $CACHED_DIRS; do done # Set context environment variables. -if [ ! -n "$LEGACY_VIRTUALENV" ]; then - set-env PATH '$HOME/.heroku/venv/bin:$PATH' - set-default-env PYTHONUNBUFFERED true - set-default-env LIBRARY_PATH /app/.heroku/vendor/lib - set-default-env LD_LIBRARY_PATH /app/.heroku/vendor/lib - set-default-env LANG en_US.UTF-8 - set-default-env PYTHONHASHSEED random - set-default-env PYTHONHOME /app/.heroku/venv/ - set-default-env PYTHONPATH /app/ -fi +set-env PATH '$HOME/.heroku/venv/bin:$PATH' +set-default-env PYTHONUNBUFFERED true +set-default-env LIBRARY_PATH /app/.heroku/vendor/lib +set-default-env LD_LIBRARY_PATH /app/.heroku/vendor/lib +set-default-env LANG en_US.UTF-8 +set-default-env PYTHONHASHSEED random +set-default-env PYTHONHOME /app/.heroku/venv/ +set-default-env PYTHONPATH /app/ + # ### Fin. From 35ee2f60bd2e04421214c31faf283939c9e0792d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Dec 2012 17:37:53 -0500 Subject: [PATCH 2/7] remove bunk --- bin/compile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bin/compile b/bin/compile index 5b71655..37c30ef 100755 --- a/bin/compile +++ b/bin/compile @@ -106,12 +106,6 @@ done set +e # Create set-aside `.heroku` folder. mkdir .heroku &> /dev/null -HEROKU_DIR_STATUS=$? - -# TODO: This is a new app, disable injection. -# [ $HEROKU_DIR_STATUS -eq 0 ] && { - # TODO: touch .heroku/injection_disabled -# } set -e # Buildpack profile init script @@ -141,7 +135,6 @@ OUT=$(virtualenv --python $PYTHON_EXE --distribute --never-download --prompt='(v OUT=$(virtualenv --python $PYTHON_EXE --distribute --never-download --prompt='(venv) ' $VIRTUALENV_LOC ) } echo "$OUT" | cleanup | indent - set -e # Pylibmc support. From 12f053ef7f598b55087daab97182e9fa0aaa1932 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Dec 2012 17:51:40 -0500 Subject: [PATCH 3/7] remove almost all django support --- bin/compile | 2 +- bin/detect | 41 +++-------------------------- bin/steps/django | 37 ++++++++++++++++++++++++++ bin/steps/django/collectstatic | 28 -------------------- bin/steps/django/init | 32 ----------------------- bin/steps/django/injection | 47 ---------------------------------- 6 files changed, 41 insertions(+), 146 deletions(-) create mode 100644 bin/steps/django delete mode 100755 bin/steps/django/collectstatic delete mode 100755 bin/steps/django/init delete mode 100755 bin/steps/django/injection diff --git a/bin/compile b/bin/compile index 37c30ef..c7f0837 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 588e15e..ccfbff9 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 3 -type f -name 'settings.py' | head -1) - -SETTINGS_FILE=$(find $BUILD_DIR/. -maxdepth 2 -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 0000000..b144212 --- /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 44346e2..0000000 --- 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 bb12f55..0000000 --- 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 5479609..0000000 --- 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 < Date: Thu, 6 Dec 2012 17:53:38 -0500 Subject: [PATCH 4/7] simplfy comments --- bin/compile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/compile b/bin/compile index c7f0837..3e6f31b 100755 --- a/bin/compile +++ b/bin/compile @@ -153,11 +153,7 @@ fi puts-step "Installing dependencies using pip ($(pip --version | awk '{print $2}'))" pip install --use-mirrors -r requirements.txt --exists-action=w --src=./.heroku/src | cleanup | indent -# Do additional application hackery if applications appears to be a Django app. -# Optionally, disable all Django-specific changes with `DISABLE_INJECTION` env. -# -# See [`bin/steps/django`](django.html). - +# Django collectstatic support. if [ "$NAME" = "Python/Django" ]; then source $BIN_DIR/steps/django fi From 76d2eda80e96e27d7c0ae90e4a83182835cfaeed Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Dec 2012 17:54:53 -0500 Subject: [PATCH 5/7] LEGACY_TRIGGER --- bin/compile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/compile b/bin/compile index 3e6f31b..c6b39f8 100755 --- a/bin/compile +++ b/bin/compile @@ -49,8 +49,8 @@ CACHED_DIRS=".heroku" PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-$CACHE_DIR/pip_downloads} # Static configurations for virtualenv caches. -MODERN_VIRTUALENV_LOC=".heroku/venv" -LEGACY_VIRTUALENV_TRIGGER="lib/python2.7" +VIRTUALENV_LOC=".heroku/venv" +LEGACY_TRIGGER="lib/python2.7" PROFILE_PATH="$BUILD_DIR/.profile.d/python.sh" @@ -92,11 +92,11 @@ mkdir -p $CACHE_DIR # Nice defaults. -VIRTUALENV_LOC=$MODERN_VIRTUALENV_LOC -VIRTUALENV_DIRS=$MODERN_VIRTUALENV_LOC +VIRTUALENV_LOC=$VIRTUALENV_LOC +VIRTUALENV_DIRS=$VIRTUALENV_LOC # Purge "old-style" virtualenvs. -[ -d $CACHE_DIR/$LEGACY_VIRTUALENV_TRIGGER ] && rm -fr $CACHE_DIR/* +[ -d $CACHE_DIR/$LEGACY_TRIGGER ] && rm -fr $CACHE_DIR/* # Restore old artifacts from the cache. for dir in $CACHED_DIRS; do From 287b39882601aac95d215a1435e97135552cf2c9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Dec 2012 17:58:44 -0500 Subject: [PATCH 6/7] better comments --- bin/compile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/compile b/bin/compile index c6b39f8..4a002a5 100755 --- a/bin/compile +++ b/bin/compile @@ -44,7 +44,7 @@ CACHE_DIR=$2 # The detected application type (`Python`|`Python/Django`). NAME=$($BIN_DIR/detect $BUILD_DIR) -# Where to store the Pip download cache. +# Where to store the pip download cache. CACHED_DIRS=".heroku" PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-$CACHE_DIR/pip_downloads} @@ -53,7 +53,6 @@ VIRTUALENV_LOC=".heroku/venv" LEGACY_TRIGGER="lib/python2.7" PROFILE_PATH="$BUILD_DIR/.profile.d/python.sh" - # Python version. This will be used in the future to specify custom Pythons. PYTHON_VERSION="2.7.2" PYTHON_EXE="python2.7" From ca3b3808b926da8f3ccd2ae2deb8cca3ecc8255d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 6 Dec 2012 18:01:48 -0500 Subject: [PATCH 7/7] simplify purge --- bin/compile | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/bin/compile b/bin/compile index 4a002a5..353288a 100755 --- a/bin/compile +++ b/bin/compile @@ -75,10 +75,6 @@ cd $BUILD_DIR # Experimental pre_compile hook. source $BIN_DIR/steps/hooks/pre_compile -# ### Sanity Checks -# -# Just a little peace of mind. - # If no requirements given, assume `setup.py develop`. if [ ! -f requirements.txt ]; then puts-step "No requirements.txt provided; assuming dist package." @@ -89,11 +85,6 @@ fi mkdir -p $CACHE_DIR [ ! "$(ls -A $CACHE_DIR)" ] && export FRESH_APP=1 - -# Nice defaults. -VIRTUALENV_LOC=$VIRTUALENV_LOC -VIRTUALENV_DIRS=$VIRTUALENV_LOC - # Purge "old-style" virtualenvs. [ -d $CACHE_DIR/$LEGACY_TRIGGER ] && rm -fr $CACHE_DIR/* @@ -128,9 +119,9 @@ OUT=$(virtualenv --python $PYTHON_EXE --distribute --never-download --prompt='(v then echo " ! CLEAN_VIRTUALENV set, rebuilding virtualenv." else echo " ! Virtualenv corrupt, rebuilding." fi - for dir in $VIRTUALENV_DIRS; do - rm -fr $dir &> /dev/null || true - done + + rm -fr $VIRTUALENV_LOC &> /dev/null || true + OUT=$(virtualenv --python $PYTHON_EXE --distribute --never-download --prompt='(venv) ' $VIRTUALENV_LOC ) } echo "$OUT" | cleanup | indent