pip-install 2.19 KB
Newer Older
Kenneth Reitz's avatar
Kenneth Reitz committed
1 2
#!/usr/bin/env bash

Kenneth Reitz's avatar
Kenneth Reitz committed
3
# shellcheck source=bin/utils
4
source "$BIN_DIR/utils"
Kenneth Reitz's avatar
Kenneth Reitz committed
5

Kenneth Reitz's avatar
Kenneth Reitz committed
6
if [ ! "$SKIP_PIP_INSTALL" ]; then
7

Kenneth Reitz's avatar
Kenneth Reitz committed
8 9
    # Install dependencies with Pip.
    puts-step "Installing requirements with pip"
10

11 12 13 14 15
    # 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
16
    if [[ -r "$ENV_DIR/PIP_EXTRA_INDEX_URL" ]]; then
17 18
        PIP_EXTRA_INDEX_URL="$(cat "$ENV_DIR/PIP_EXTRA_INDEX_URL")"
        export PIP_EXTRA_INDEX_URL
19 20 21 22 23 24
        mcount "buildvar.PIP_EXTRA_INDEX_URL"
    fi

    set +e

    # Set SLUGIFY_USES_TEXT_UNIDECODE, required for Airflow versions >=1.10
Casey Faist's avatar
Casey Faist committed
25
    if [[ -r "$ENV_DIR/SLUGIFY_USES_TEXT_UNIDECODE" ]]; then
26 27 28
        SLUGIFY_USES_TEXT_UNIDECODE="$(cat "$ENV_DIR/SLUGIFY_USES_TEXT_UNIDECODE")"
        export SLUGIFY_USES_TEXT_UNIDECODE
        mcount "buildvar.SLUGIFY_USES_TEXT_UNIDECODE"
29 30
    fi

Kenneth Reitz's avatar
Kenneth Reitz committed
31
    set +e
Kenneth Reitz's avatar
Kenneth Reitz committed
32

Kenneth Reitz's avatar
Kenneth Reitz committed
33 34
    # Measure that we're using pip.
    mcount "tool.pip"
Kenneth Reitz's avatar
Kenneth Reitz committed
35

Kenneth Reitz's avatar
Kenneth Reitz committed
36 37 38 39 40
    # Count expected build failures.
    if grep -q '==0.0.0' requirements.txt; then
        mcount "failure.none-version"
    fi

41 42 43
    if [ ! -f "$BUILD_DIR/.heroku/python/bin/pip" ]; then
        exit 1
    fi
David Zülke's avatar
David Zülke committed
44
    /app/.heroku/python/bin/pip install -r "$BUILD_DIR/requirements.txt" --exists-action=w --src=/app/.heroku/src --disable-pip-version-check --no-cache-dir 2>&1 | tee "$WARNINGS_LOG" | cleanup | indent
Kenneth Reitz's avatar
Kenneth Reitz committed
45 46
    PIP_STATUS="${PIPESTATUS[0]}"
    set -e
Kenneth Reitz's avatar
Kenneth Reitz committed
47

Kenneth Reitz's avatar
Kenneth Reitz committed
48
    show-warnings
Kenneth Reitz's avatar
Kenneth Reitz committed
49

Kenneth Reitz's avatar
Kenneth Reitz committed
50
    if [[ ! $PIP_STATUS -eq 0 ]]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
51
        mcount "failure.pip-install"
Kenneth Reitz's avatar
Kenneth Reitz committed
52 53
        exit 1
    fi
54

Kenneth Reitz's avatar
Kenneth Reitz committed
55 56
    # Smart Requirements handling
    cp requirements.txt .heroku/python/requirements-declared.txt
David Zülke's avatar
David Zülke committed
57
    /app/.heroku/python/bin/pip freeze --disable-pip-version-check > .heroku/python/requirements-installed.txt
Kenneth Reitz's avatar
Kenneth Reitz committed
58 59

    echo
Kenneth Reitz's avatar
Kenneth Reitz committed
60 61

    # Install test dependencies, for CI.
62 63 64
    if [ "$INSTALL_TEST" ]; then
        if [[ -f "$1/requirements-test.txt" ]]; then
            puts-step "Installing test dependencies…"
David Zülke's avatar
David Zülke committed
65
            /app/.heroku/python/bin/pip install -r "$1/requirements-test.txt" --exists-action=w --src=./.heroku/src --disable-pip-version-check --no-cache-dir 2>&1 | cleanup | indent
66 67
        fi
    fi
68
fi