@@ -51,8 +51,8 @@ LEGACY_TRIGGER="lib/python2.7"
5151PROFILE_PATH=" $BUILD_DIR /.profile.d/python.sh"
5252
5353# Python version. This will be used in the future to specify custom Pythons.
54- PYTHON_VERSION= " 2.7.2 "
55- PYTHON_EXE=" python2.7 "
54+ DEFAULT_PYTHON_VERSION= " python-2.6.3 "
55+ PYTHON_EXE=" /app/.heroku/python/bin/python "
5656
5757# Sanitizing environment variables.
5858unset GIT_DIR PYTHONHOME PYTHONPATH LD_LIBRARY_PATH LIBRARY_PATH
@@ -63,6 +63,26 @@ export PIP_DOWNLOAD_CACHE BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH
6363# Syntax sugar.
6464source $BIN_DIR /utils
6565
66+ # Directory Hacks for path consistiency.
67+ APP_DIR=' /app'
68+ TMP_APP_DIR=$CACHE_DIR /tmp_app_dir
69+ ls -a $APP_DIR
70+
71+ # Copy Anvil app dir to temporary storage...
72+ mkdir -p $TMP_APP_DIR
73+ deep-mv $APP_DIR $TMP_APP_DIR
74+
75+ # Copy Application code in.
76+ deep-mv $BUILD_DIR $APP_DIR
77+
78+ # Set new context.
79+ ORIG_BUILD_DIR=$BUILD_DIR
80+ BUILD_DIR=$APP_DIR
81+
82+ # Prepend proper path buildpack use.
83+ export PATH=$BUILD_DIR /.heroku/python/bin:$PATH
84+ # ls $BUILD_DIR
85+
6686# ## Build Time
6787#
6888
@@ -78,6 +98,12 @@ if [ ! -f requirements.txt ]; then
7898 echo " -e ." > requirements.txt
7999fi
80100
101+ # If no runtime given, assume default version.
102+ if [ ! -f runtime.txt ]; then
103+ puts-step " No runtime.txt provided; assuming $DEFAULT_PYTHON_VERSION ."
104+ echo $DEFAULT_PYTHON_VERSION > runtime.txt
105+ fi
106+
81107# ### The Cache
82108mkdir -p $CACHE_DIR
83109[ ! " $( ls -A $CACHE_DIR ) " ] && export FRESH_APP=1
@@ -105,13 +131,51 @@ mkdir -p $(dirname $PROFILE_PATH)
105131# TODO: Bootstrap a bottled Python VM...
106132
107133set +e
108- puts-step " Preparing Python interpreter ($PYTHON_VERSION )"
109- puts-step " Creating Virtualenv ($( virtualenv --version) )"
134+ PYTHON_VERSION=$( cat runtime.txt)
135+ puts-step " Preparing Python runtime ($PYTHON_VERSION )"
136+
137+ # Install Python.
138+ if [ -f .heroku/python-version ]; then
139+ if [ ! $( cat .heroku/python-version) = $PYTHON_VERSION ]; then
140+ puts-step " Found $( cat .heroku/python-version) , removing."
141+ rm -fr .heroku/python
142+ else
143+ SKIP_INSTALL=1
144+ fi
145+ fi
146+
147+
148+ if [ ! " $SKIP_INSTALL " ]; then
149+ puts-step " Installing runtime $PYTHON_VERSION "
150+ curl http://envy-versions.s3.amazonaws.com/$PYTHON_VERSION .tar.bz2 | tar jx
151+ mv python .heroku/python
152+
153+ # Record for future reference.
154+ echo $PYTHON_VERSION > .heroku/python-version
155+
156+ # Prepare it for the real world
157+ # curl -O http://python-distribute.org/distribute_setup.py
158+ python $ROOT_DIR /vendor/distribute-0.6.31/setup.py install
159+ easy_install $ROOT_DIR /vendor/pip-1.2.1.tar.gz
160+ fi
110161
111- # Try to create the virtualenv.
112- OUT=$( virtualenv --python $PYTHON_EXE --distribute --never-download --prompt=' (venv) ' $VIRTUALENV_LOC 2>&1 )
113162
114- echo " $OUT " | cleanup | indent
163+ # puts-step "Creating Virtualenv ($(virtualenv --version))"
164+
165+ # # Try to create the virtualenv.
166+ # OUT=$(virtualenv --python $PYTHON_EXE --distribute --never-download --prompt='(venv) ' $VIRTUALENV_LOC 2>&1)
167+
168+ # [ $? -ne 0 -o -n "$CLEAN_VIRTUALENV" ] && {
169+ # if [ -n "$CLEAN_VIRTUALENV" ]
170+ # then echo " ! CLEAN_VIRTUALENV set, rebuilding virtualenv."
171+ # else echo " ! Virtualenv corrupt, rebuilding."
172+ # fi
173+
174+ # rm -fr $VIRTUALENV_LOC &> /dev/null || true
175+
176+ # OUT=$(virtualenv --python $PYTHON_EXE --distribute --never-download --prompt='(venv) ' $VIRTUALENV_LOC )
177+ # }
178+ # echo "$OUT" | cleanup | indent
115179set -e
116180
117181# Pylibmc support.
128192
129193# Install dependencies with Pip.
130194puts-step " Installing dependencies using pip ($( pip --version | awk ' {print $2}' ) )"
131- pip install --use-mirrors -r requirements.txt --exists-action=w --src=./.heroku/src | cleanup | indent
195+ # pip install --use-mirrors -r requirements.txt --exists-action=w --src=./.heroku/src | cleanup | indent
132196
133197# Django collectstatic support.
134198source $BIN_DIR /steps/collectstatic
135199
136- # Make Virtualenv's paths relative for portability.
137- set +e
138- OUT=$( virtualenv --python $PYTHON_EXE --relocatable $VIRTUALENV_LOC )
139- [ $? -ne 0 ] && {
140- puts-warn " Error making virtualenv relocatable"
141- echo " $OUT " | indent
142- exit 1
143- }
144- set -e
145-
146200# ### Finalize
147201#
202+ python --version
148203
149204# Store new artifacts in cache.
150205for dir in $CACHED_DIRS ; do
@@ -165,8 +220,9 @@ set-default-env PYTHONPATH /app/
165220
166221# ### Fin.
167222
223+ deep-mv $BUILD_DIR $ORIG_BUILD_DIR
224+ deep-mv $TMP_APP_DIR $APP_DIR
225+
226+
168227# Experimental post_compile hook.
169228source $BIN_DIR /steps/hooks/post_compile
170-
171- python --version
172- # <a href="http://github.com/heroku/heroku-buildpack-python"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://d3nwyuy0nl342s.cloudfront.net/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a>
0 commit comments