|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +# shellcheck source=bin/utils |
| 6 | +source "$BIN_DIR/utils" |
| 7 | + |
| 8 | +if [ ! -f requirements.txt ] && [ -f pyproject.toml ] && [ -f poetry.lock ]; then |
| 9 | + # Measure that we're using Poetry. |
| 10 | + mcount "tool.poetry" |
| 11 | + |
| 12 | + # Hash poetry.lock to detect changes. |
| 13 | + POETRY_LOCK_SHA=$(openssl dgst -sha256 poetry.lock) |
| 14 | + |
| 15 | + # Use cached requirements.txt if poetry.lock is unchanged. |
| 16 | + CACHED_REQUIREMENTS=$CACHE_DIR/requirements.txt |
| 17 | + CACHED_POETRY_LOCK_SHA=$CACHE_DIR/poetry.lock.sha256 |
| 18 | + |
| 19 | + if [ -f "$CACHED_REQUIREMENTS" ] && [ -f "$CACHED_POETRY_LOCK_SHA" ] && |
| 20 | + [ "$POETRY_LOCK_SHA" == "$(cat "$CACHED_POETRY_LOCK_SHA")" ]; then |
| 21 | + echo "Skipping requirements export, as poetry.lock hasn't changed since last deploy." | indent |
| 22 | + cp "$CACHED_REQUIREMENTS" requirements.txt |
| 23 | + else |
| 24 | + # Set environment variables for pip |
| 25 | + # This reads certain environment variables set on the Heroku app config |
| 26 | + # and makes them accessible to the pip install process. |
| 27 | + # |
| 28 | + # PIP_EXTRA_INDEX_URL allows for an alternate pypi URL to be used. |
| 29 | + if [[ -r "$ENV_DIR/PIP_EXTRA_INDEX_URL" ]]; then |
| 30 | + PIP_EXTRA_INDEX_URL="$(cat "$ENV_DIR/PIP_EXTRA_INDEX_URL")" |
| 31 | + export PIP_EXTRA_INDEX_URL |
| 32 | + mcount "buildvar.PIP_EXTRA_INDEX_URL" |
| 33 | + fi |
| 34 | + |
| 35 | + # Set SLUGIFY_USES_TEXT_UNIDECODE, required for Airflow versions >=1.10 |
| 36 | + if [[ -r "$ENV_DIR/SLUGIFY_USES_TEXT_UNIDECODE" ]]; then |
| 37 | + SLUGIFY_USES_TEXT_UNIDECODE="$(cat "$ENV_DIR/SLUGIFY_USES_TEXT_UNIDECODE")" |
| 38 | + export SLUGIFY_USES_TEXT_UNIDECODE |
| 39 | + mcount "buildvar.SLUGIFY_USES_TEXT_UNIDECODE" |
| 40 | + fi |
| 41 | + |
| 42 | + # Install Poetry. |
| 43 | + # |
| 44 | + # Poetry is not used to install the project because it does not clean up |
| 45 | + # stale requirements (see sdispater/poetry#648), so we need to export |
| 46 | + # requirements.txt anyway for the pip-uninstall step. |
| 47 | + # |
| 48 | + # Since we only use Poetry to export a requirements.txt file, ignore the |
| 49 | + # Poetry version specified in pyproject.toml. Install a pre-release of |
| 50 | + # 1.0.0 because the export command is not available before 1.0.0a0. |
| 51 | + export POETRY_VERSION="1.0.0b1" |
| 52 | + puts-step "Exporting requirements with Poetry $POETRY_VERSION…" |
| 53 | + /app/.heroku/python/bin/pip install "poetry==$POETRY_VERSION" \ |
| 54 | + --disable-pip-version-check &> /dev/null |
| 55 | + |
| 56 | + # Export requirements. |
| 57 | + /app/.heroku/python/bin/poetry export -f requirements.txt > requirements.txt |
| 58 | + |
| 59 | + # Write SHA and requirements.txt to cache dir. |
| 60 | + echo "$POETRY_LOCK_SHA" > "$CACHED_POETRY_LOCK_SHA" |
| 61 | + cp requirements.txt "$CACHED_REQUIREMENTS" |
| 62 | + fi |
| 63 | +fi |
0 commit comments