#!/usr/bin/env bash
# shellcheck disable=SC2086

PY_FILES=$(git diff --name-only --cached --diff-filter=ACMR | grep "\.py$")

set -eo pipefail

if [[ -n "$PY_FILES" ]]; then
    # set up the virtualenv if it's not already available
    if [[ ! -v VIRTUAL_ENV ]]; then
        source .venv/bin/activate
    fi
    # Run ruff (against all files, it's fast enough)
    ruff format . && ruff check . --diff \
        && echo "ruff passed!"
else
    exit 0
fi

exit 0
