#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
# Modified to use relative paths instead of hardcoded paths

# start templated
# Try to detect Python from common virtual environments
venv_paths=("./.venv/bin/python" "./.venv/bin/python3" "../.venv/bin/python" "../.venv/bin/python3" "../../.venv/bin/python" "../../.venv/bin/python3")
args=(hook-impl --config=.wl/.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
args+=(--hook-dir "$HERE" -- "$@")

# Try to find the Python executable in virtual environments
for PYTHON in "${venv_paths[@]}"; do
    if [ -x "$PYTHON" ]; then
        exec "$PYTHON" -mpre_commit "${args[@]}"
        exit 0
    fi
done

# If no virtual environment Python found, try system pre-commit
if command -v pre-commit > /dev/null; then
    exec pre-commit "${args[@]}" 2>&1
fi

# If all fails, show error message
echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
exit 1
