pipenv 2.92 KB
Newer Older
Kenneth Reitz's avatar
Kenneth Reitz committed
1 2
#!/usr/bin/env bash

Kenneth Reitz's avatar
Kenneth Reitz committed
3 4
# export CLINT_FORCE_COLOR=1
# export PIPENV_FORCE_COLOR=1
Kenneth Reitz's avatar
Kenneth Reitz committed
5
# shellcheck source=bin/utils
Ally Weir's avatar
Ally Weir committed
6
source "$BIN_DIR/utils"
Kenneth Reitz's avatar
set -e  
Kenneth Reitz committed
7
set -e
8

9 10 11
if [[ -f Pipfile.lock ]]; then
    if [[ -f .heroku/python/Pipfile.lock.sha256 ]]; then
        if [[ $(openssl dgst -sha256 Pipfile.lock) == $(cat .heroku/python/Pipfile.lock.sha256) ]]; then
12 13 14

            # Don't skip installation of there are git deps.
            if ! grep -q 'git' Pipfile.lock; then
15
                echo "Skipping installation, as Pipfile.lock hasn't changed since last deploy." | indent
16

Kenneth Reitz's avatar
set -e  
Kenneth Reitz committed
17
                export SKIP_PIPENV_INSTALL=1
Kenneth Reitz's avatar
Kenneth Reitz committed
18
                export SKIP_PIP_INSTALL=1
19
            fi
20

Kenneth Reitz's avatar
Kenneth Reitz committed
21
        fi
22 23
    fi
fi
Kenneth Reitz's avatar
Kenneth Reitz committed
24

Kenneth Reitz's avatar
Kenneth Reitz committed
25

26 27 28 29
if [ ! "$SKIP_PIPENV_INSTALL" ]; then
    # Pipenv support (Generate requriements.txt with pipenv).
    if [[ -f Pipfile ]]; then

30 31
        # Skip pip install, later.
        export SKIP_PIP_INSTALL=1
32

33 34 35 36 37
        # Set Pip env vars
        # This reads certain environment variables set on the Heroku app config
        # and makes them accessible to the pip install process.
        #
        # PIP_EXTRA_INDEX_URL allows for an alternate pypi URL to be used.
38 39 40
        if [[ -r $ENV_DIR/PIP_EXTRA_INDEX_URL ]]; then
            PIP_EXTRA_INDEX_URL="$(cat "$ENV_DIR/PIP_EXTRA_INDEX_URL")"
            export PIP_EXTRA_INDEX_URL
41 42 43 44 45 46 47 48
            mcount "buildvar.PIP_EXTRA_INDEX_URL"
        fi

        # Set SLUGIFY_USES_TEXT_UNIDECODE, required for Airflow versions >=1.10
        if [[ -r $ENV_DIR/SLUGIFY_USES_TEXT_UNIDECODE ]]; then
            SLUGIFY_USES_TEXT_UNIDECODE="$(cat "$ENV_DIR/SLUGIFY_USES_TEXT_UNIDECODE")"
            export SLUGIFY_USES_TEXT_UNIDECODE
            mcount "buildvar.SLUGIFY_USES_TEXT_UNIDECODE"
49
        fi
Kenneth Reitz's avatar
Kenneth Reitz committed
50

51
        export DEFAULT_PIPENV_VERSION="2018.7.1"
52

53 54
        # Install pipenv; do not upgrade.
        /app/.heroku/python/bin/pip install pipenv==$PIPENV_VERSION &> /dev/null
55

56 57
        # Install the dependencies.
        if [[ ! -f Pipfile.lock ]]; then
58
            puts-step "Installing dependencies with Pipenv $PIPENV_VERSION…"
59 60 61 62 63 64
            /app/.heroku/python/bin/pipenv install --system --skip-lock 2>&1 | indent
        else
            pipenv-to-pip Pipfile.lock > requirements.txt
            "$BIN_DIR/steps/pip-uninstall"
            cp requirements.txt .heroku/python/requirements-declared.txt
            openssl dgst -sha256 Pipfile.lock > .heroku/python/Pipfile.lock.sha256
65

66
            puts-step "Installing dependencies with Pipenv $PIPENV_VERSION…"
67 68
            /app/.heroku/python/bin/pipenv install --system --deploy 2>&1 | indent
        fi
69 70
        # Measure that we're using Pipenv.
        mcount "tool.pipenv"
71

72 73 74 75
        # Install the test dependencies, for CI.
        if [ "$INSTALL_TEST" ]; then
            puts-step "Installing test dependencies…"
            /app/.heroku/python/bin/pipenv install --dev --system --deploy 2>&1 | cleanup | indent
76
        fi
Kenneth Reitz's avatar
Kenneth Reitz committed
77
    fi
78 79
else
    export SKIP_PIP_INSTALL=1
Kenneth Reitz's avatar
Kenneth Reitz committed
80
    pipenv-to-pip Pipfile.lock > requirements.txt
81
fi