pipenv 3.25 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
            # Measure that we're using Pipenv.
            mcount "tool.pipenv"

David Zülke's avatar
David Zülke committed
15
            # Don't skip installation of there are git deps.
16
            if ! grep -q 'git' Pipfile.lock; then
17
                echo "Skipping installation, as Pipfile.lock hasn't changed since last deploy." | indent
18

Kenneth Reitz's avatar
Kenneth Reitz committed
19
                mcount "tool.pipenv"
Kenneth Reitz's avatar
set -e  
Kenneth Reitz committed
20
                export SKIP_PIPENV_INSTALL=1
Kenneth Reitz's avatar
Kenneth Reitz committed
21
                export SKIP_PIP_INSTALL=1
22
            fi
Kenneth Reitz's avatar
Kenneth Reitz committed
23
        fi
24 25
    fi
fi
Kenneth Reitz's avatar
Kenneth Reitz committed
26

Kenneth Reitz's avatar
Kenneth Reitz committed
27

28
if [ ! "$SKIP_PIPENV_INSTALL" ]; then
29
    # Pipenv support (Generate requirements.txt with pipenv).
30
    if [[ -f Pipfile ]]; then
31 32
        # Measure that we're using Pipenv.
        mcount "tool.pipenv"
33

34 35
        # Skip pip install, later.
        export SKIP_PIP_INSTALL=1
36

37 38 39 40 41
        # 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.
Casey Faist's avatar
Casey Faist committed
42
        if [[ -r "$ENV_DIR/PIP_EXTRA_INDEX_URL" ]]; then
43 44
            PIP_EXTRA_INDEX_URL="$(cat "$ENV_DIR/PIP_EXTRA_INDEX_URL")"
            export PIP_EXTRA_INDEX_URL
45 46 47 48
            mcount "buildvar.PIP_EXTRA_INDEX_URL"
        fi

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

Ally Weir's avatar
Ally Weir committed
55
        export PIPENV_VERSION="2018.5.18"
56

57
        # Install pipenv.
Casey Faist's avatar
Casey Faist committed
58 59 60
        # Due to weird old pip behavior and pipenv behavior, pipenv upgrades pip
        # to latest if only --upgrade is specified. Specify upgrade strategy to
        # avoid this eager behavior.
David Zülke's avatar
David Zülke committed
61
        /app/.heroku/python/bin/pip install pipenv==$PIPENV_VERSION --upgrade --upgrade-strategy only-if-needed &> /dev/null
62

63 64 65
        # Install the test dependencies, for CI.
        if [ "$INSTALL_TEST" ]; then
            puts-step "Installing test dependencies…"
David Zülke's avatar
David Zülke committed
66
            /app/.heroku/python/bin/pipenv install --dev --system --deploy 2>&1 | cleanup | indent
67

68
        # Install the dependencies.
69
        elif [[ ! -f Pipfile.lock ]]; then
70
            puts-step "Installing dependencies with Pipenv $PIPENV_VERSION…"
David Zülke's avatar
David Zülke committed
71 72
            /app/.heroku/python/bin/pipenv install --system --skip-lock 2>&1 | indent

73 74 75 76 77
        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
78

79
            puts-step "Installing dependencies with Pipenv $PIPENV_VERSION…"
David Zülke's avatar
David Zülke committed
80
            /app/.heroku/python/bin/pipenv install --system --deploy 2>&1 | indent
81
        fi
Kenneth Reitz's avatar
Kenneth Reitz committed
82
    fi
83 84
else
    export SKIP_PIP_INSTALL=1
Kenneth Reitz's avatar
Kenneth Reitz committed
85
    pipenv-to-pip Pipfile.lock > requirements.txt
86
fi