fleet-memory/scripts/hooks/lint-python.sh
Nicolò Boschi 47be07f97f
bump pg0 0.11.x and improve documentation (#33)
* bump pg0 0.11.x and improve documentation

* bump pg0 0.11.x and improve documentation

* bump pg0 0.11.x and improve documentation

* ci: test notebooks on ci

* ci: test notebooks on ci

* rm llms-full from repo

* formatting

* formatting
2025-12-16 13:33:01 +01:00

46 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
# Lint Python code with Ruff (hindsight-api and hindsight packages only)
set -e
REPO_ROOT="$(git rev-parse --show-toplevel)"
# Get staged Python files in hindsight-api or hindsight directories only
STAGED_PY_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^(hindsight-api|hindsight)/.*\.py$' || true)
if [ -z "$STAGED_PY_FILES" ]; then
echo " No Python files to lint"
exit 0
fi
cd "$REPO_ROOT/hindsight-api"
# Check if ruff is available
if ! uv run ruff --version &> /dev/null; then
echo " Ruff not installed, skipping Python lint"
exit 0
fi
echo " Linting Python files with Ruff..."
# Convert to absolute paths
ABSOLUTE_FILES=""
for file in $STAGED_PY_FILES; do
ABSOLUTE_FILES="$ABSOLUTE_FILES $REPO_ROOT/$file"
done
# Run ruff check with fix
uv run ruff check --fix $ABSOLUTE_FILES
# Run ruff format
uv run ruff format $ABSOLUTE_FILES
# Re-add fixed files to staging
cd "$REPO_ROOT"
for file in $STAGED_PY_FILES; do
if [ -f "$file" ]; then
git add "$file"
fi
done
echo " Python lint complete"