#!/usr/bin/env bash

set +e
# Install dependencies with Pip.
# shellcheck source=bin/utils
source $BIN_DIR/utils

if [ ! "$SKIP_PIP_INSTALL" ]; then

  if [[ -f .heroku/python/requirements-declared.txt ]]; then

    cp .heroku/python/requirements-declared.txt requirements-declared.txt


    if ! pip-diff --stale requirements-declared.txt requirements.txt --exclude setuptools pip wheel > .heroku/python/requirements-stale.txt; then
      mount "failure.bad-requirements"
    fi

    rm -fr requirements-declared.txt

    if [[ -s .heroku/python/requirements-stale.txt ]]; then
      puts-step "Uninstalling stale dependencies"
      /app/.heroku/python/bin/pip uninstall -r .heroku/python/requirements-stale.txt -y --exists-action=w --disable-pip-version-check | cleanup | indent
    fi
  fi

fi
set -e
