python 1.55 KB
Newer Older
1
set +e
Kenneth Reitz's avatar
Kenneth Reitz committed
2
runtime-fixer runtime.txt
3 4 5 6 7
PYTHON_VERSION=$(cat runtime.txt)

# Install Python.
if [ -f .heroku/python-version ]; then
  if [ ! $(cat .heroku/python-version) = $PYTHON_VERSION ]; then
Kenneth Reitz's avatar
v100  
Kenneth Reitz committed
8 9
      puts-step "Found $(cat .heroku/python-version), removing"
      rm -fr .heroku/python
10 11 12 13 14 15
  else
    SKIP_INSTALL=1
  fi
fi

if [ ! $STACK = $CACHED_PYTHON_STACK ]; then
Kenneth Reitz's avatar
v100  
Kenneth Reitz committed
16 17
    rm -fr .heroku/python .heroku/python-stack .heroku/vendor
    unset SKIP_INSTALL
18 19 20 21
fi


if [ ! "$SKIP_INSTALL" ]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
22
    puts-step "Installing $PYTHON_VERSION"
23 24 25 26

    # Prepare destination directory.
    mkdir -p .heroku/python

27
    curl https://lang-python.s3.amazonaws.com/$STACK/runtimes/$PYTHON_VERSION.tar.gz -s | tar zxv -C .heroku/python &> /dev/null
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    if [[ $? != 0 ]] ; then
      puts-warn "Requested runtime ($PYTHON_VERSION) is not available for this stack ($STACK)."
      puts-warn "Aborting.  More info: https://devcenter.heroku.com/articles/python-support"
      exit 1
    fi

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

  hash -r
fi

# If Pip isn't up to date:
Kenneth Reitz's avatar
v100  
Kenneth Reitz committed
43
if [ "$FRESH_PYTHON" ] || [[ ! $(pip --version) == *$PIP_VERSION* ]]; then
44 45
  WORKING_DIR=$(pwd)

46 47 48
  TMPTARDIR=$(mktemp -d)
  trap "rm -rf $TMPTARDIR" RETURN

Kenneth Reitz's avatar
Kenneth Reitz committed
49 50
  puts-step "Installing pip"

Kenneth Reitz's avatar
Kenneth Reitz committed
51 52 53
  # Remove old installations.
  rm -fr /app/.heroku/python/lib/python2.7/site-packages/pip-*
  rm -fr /app/.heroku/python/lib/python2.7/site-packages/setuptools-*
Kenneth Reitz's avatar
Kenneth Reitz committed
54

Kenneth Reitz's avatar
Kenneth Reitz committed
55
  /app/.heroku/python/bin/python $ROOT_DIR/vendor/get-pip.py &> /dev/null
Kenneth Reitz's avatar
Kenneth Reitz committed
56

57 58 59
fi

set -e
60
hash -r