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

3 4
# Detect Python-version with Pipenv.

5
if [[ -f "$BUILD_DIR/Pipfile" ]]; then
6

7 8
    if [[ ! -f "$BUILD_DIR/runtime.txt" ]]; then
        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
11
        if [[ -f "$BUILD_DIR/Pipfile.lock" ]]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
12
            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_27" > "$BUILD_DIR/runtime.txt"
Kenneth Reitz's avatar
Kenneth Reitz committed
23 24
                fi
                if [ "$PYTHON" = 3.6 ]; then
25 26 27 28
                    echo "$LATEST_36" > "$BUILD_DIR/runtime.txt"
                fi
                if [ "$PYTHON" = 3.7 ]; then
                    echo "$LATEST_37" > "$BUILD_DIR/runtime.txt"
Kenneth Reitz's avatar
Kenneth Reitz committed
29
                fi
Kenneth Reitz's avatar
Kenneth Reitz committed
30
            fi
Kenneth Reitz's avatar
Kenneth Reitz committed
31 32


33 34 35
        fi
    fi
fi