Skip to content
Snippets Groups Projects
pipenv-python-version 1.15 KiB
Newer Older
#!/usr/bin/env bash

# Detect Python-version with Pipenv.

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

    if [[ ! -f $BUILD_DIR/runtime.txt ]]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
        if [[ ! -f $BUILD_DIR/Pipfile.lock ]]; then
Kenneth Reitz's avatar
Kenneth Reitz committed
            puts-warn "No 'Pipfile.lock' found! We recommend you commit this into your repository."
Kenneth Reitz's avatar
Kenneth Reitz committed
        fi
Kenneth Reitz's avatar
Kenneth Reitz committed
        if [[ -f $BUILD_DIR/Pipfile.lock ]]; then
            set +e
Kenneth Reitz's avatar
Kenneth Reitz committed
            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
            set -e
Kenneth Reitz's avatar
Kenneth Reitz committed

Kenneth Reitz's avatar
Kenneth Reitz committed
            if [[ "$PYTHON" == "null" ]]; then
                PYTHON=$(jq -r '._meta.requires.python_version' "$BUILD_DIR/Pipfile.lock")
                if [ "$PYTHON" = 2.7 ]; then
                    echo "$LATEST_27" > "$BUILD_DIR/runtime.txt"
Kenneth Reitz's avatar
Kenneth Reitz committed
                fi
                if [ "$PYTHON" = 3.6 ]; then
                    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
                fi
Kenneth Reitz's avatar
Kenneth Reitz committed
            fi