pipenv-python-version 1.02 KB
Newer Older
Kenneth Reitz's avatar
Kenneth Reitz committed
1 2
#!/usr/bin/env bash

3 4
# Detect Python-version with Pipenv.

Kenneth Reitz's avatar
Kenneth Reitz committed
5
if [[ -f $BUILD_DIR/Pipfile ]]; then
6 7

    if [[ ! -f $BUILD_DIR/runtime.txt ]]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
8
        if [[ ! -f $BUILD_DIR/Pipfile.lock ]]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
9
            puts-warn "No 'Pipfile.lock' found! We recommend you commit this into your repository."
Kenneth Reitz's avatar
Kenneth Reitz committed
10
        fi
Kenneth Reitz's avatar
Kenneth Reitz committed
11 12
        if [[ -f $BUILD_DIR/Pipfile.lock ]]; then
            set +e
Kenneth Reitz's avatar
Kenneth Reitz committed
13 14 15 16
            PYTHON=$(jq -r '._meta.requires.python_full_version' "$BUILD_DIR/Pipfile.lock")
            if [[ "$PYTHON" != "null" ]]; then
                echo "python-$PYTHON" > "$BUILD_DIR/runtime.txt"
            fi
Kenneth Reitz's avatar
Kenneth Reitz committed
17
            set -e
Kenneth Reitz's avatar
Kenneth Reitz committed
18

Kenneth Reitz's avatar
Kenneth Reitz committed
19 20 21
            if [[ "$PYTHON" == "null" ]]; then
                PYTHON=$(jq -r '._meta.requires.python_version' "$BUILD_DIR/Pipfile.lock")
                if [ "$PYTHON" = 2.7 ]; then
22
                    echo "$LATEST_2" > "$BUILD_DIR/runtime.txt"
Kenneth Reitz's avatar
Kenneth Reitz committed
23 24
                fi
                if [ "$PYTHON" = 3.6 ]; then
25
                    echo "$LATEST_3" > "$BUILD_DIR/runtime.txt"
Kenneth Reitz's avatar
Kenneth Reitz committed
26
                fi
Kenneth Reitz's avatar
Kenneth Reitz committed
27
            fi
Kenneth Reitz's avatar
Kenneth Reitz committed
28 29


30 31 32 33
        fi
    fi
fi