source $BIN_DIR/utils PYTHON_VERSION='' if [ -f runtime.txt ]; then PYTHON_VERSION=$(cat runtime.txt) fi PYTHON_VERSION=$($BUILDPACK_PATH/bin/steps/libs/version.rb $BUILDPACK_PATH/manifest.yml $PYTHON_VERSION) PYTHON_DIR=$DEPS_DIR/$DEPS_IDX/python # Install Python. if [ -f $CACHE_DIR/python-stack ]; then if [ ! $(cat $CACHE_DIR/python-stack) = $CF_STACK ]; then rm -fr $PYTHON_DIR $CACHE_DIR/python-version $CACHE_DIR/python-stack $CACHE_DIR/vendor unset SKIP_INSTALL fi fi if [ -f $CACHE_DIR/python-version ]; then if [ ! $(cat $CACHE_DIR/python-version) = $PYTHON_VERSION ]; then puts-step "Found $(cat $CACHE_DIR/python-version), removing" rm -fr $PYTHON_DIR $CACHE_DIR/python-version $CACHE_DIR/python-stack $CACHE_DIR/vendor else SKIP_INSTALL=1 fi fi if [ -z "${SKIP_INSTALL:-}" ]; then puts-step "Installing $PYTHON_VERSION" # Prepare destination directory. mkdir $PYTHON_DIR exit_code=0 SHORT_PYTHON_VERSION=$(echo $PYTHON_VERSION | sed "s|python-||") filtered_url=$($BUILDPACK_PATH/compile-extensions/bin/download_dependency_by_name python $SHORT_PYTHON_VERSION /tmp/python.tar.gz) || exit_code=$? if [ $exit_code -ne 0 ]; then $BUILDPACK_PATH/compile-extensions/bin/recommend_dependency_by_name python $SHORT_PYTHON_VERSION exit 1 fi $BUILDPACK_PATH/compile-extensions/bin/warn_if_newer_patch_by_name python $SHORT_PYTHON_VERSION tar zxvf /tmp/python.tar.gz -C $PYTHON_DIR &> /dev/null echo "Downloaded [$filtered_url]" FRESH_PYTHON=true fi # Link pushd $DEPS_DIR/$DEPS_IDX/bin >/dev/null ln -s ../python/bin/* . popd >/dev/null pushd $DEPS_DIR/$DEPS_IDX/lib >/dev/null ln -s ../python/lib/* . popd >/dev/null # Record for future reference. echo $PYTHON_VERSION > "$CACHE_DIR/python-version" echo $CF_STACK > "$CACHE_DIR/python-stack" hash -r PIP_VERSION=$($BUILDPACK_PATH/compile-extensions/bin/default_version_for $BUILDPACK_PATH/manifest.yml pip) SETUPTOOLS_VERSION=$($BUILDPACK_PATH/compile-extensions/bin/default_version_for $BUILDPACK_PATH/manifest.yml setuptools) # If Pip isn't up to date: if [ -n "${FRESH_PYTHON:-}" ] || [[ ! $(pip --version) == *$PIP_VERSION* ]]; then TMPTARDIR=$(mktemp -d) # Prepare it for the real world puts-step "Installing Setuptools ($SETUPTOOLS_VERSION)" filtered_url=$($BUILDPACK_PATH/compile-extensions/bin/download_dependency_by_name setuptools $SETUPTOOLS_VERSION /tmp/setuptools.tgz) echo "Downloaded [$filtered_url]" tar zxf /tmp/setuptools.tgz -C $TMPTARDIR pushd $TMPTARDIR/setuptools-$SETUPTOOLS_VERSION/ >/dev/null python setup.py install --prefix=$DEPS_DIR/$DEPS_IDX/python &> /dev/null popd >/dev/null puts-step "Installing Pip ($PIP_VERSION)" filtered_url=$($BUILDPACK_PATH/compile-extensions/bin/download_dependency_by_name pip $PIP_VERSION /tmp/pip.tgz) echo "Downloaded [$filtered_url]" tar zxf /tmp/pip.tgz -C $TMPTARDIR pushd $TMPTARDIR/pip-$PIP_VERSION/ >/dev/null python setup.py install --prefix=$DEPS_DIR/$DEPS_IDX/python &> /dev/null popd >/dev/null pushd $DEPS_DIR/$DEPS_IDX/bin >/dev/null ln -sf ../python/bin/* . popd >/dev/null pushd $DEPS_DIR/$DEPS_IDX/lib >/dev/null ln -sf ../python/lib/* . popd >/dev/null fi pushd $DEPS_DIR/$DEPS_IDX/include >/dev/null ln -sf ../python/include/* . popd >/dev/null pushd $DEPS_DIR/$DEPS_IDX/pkgconfig >/dev/null ln -sf ../python/lib/pkgconfig/* . popd >/dev/null hash -r