-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.sh
More file actions
executable file
·100 lines (85 loc) · 2.1 KB
/
lint.sh
File metadata and controls
executable file
·100 lines (85 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
# lint.sh - Auto-fix Python bindings (parallel, quiet on success)
# Usage: ./lint.sh [--check] [--test]
# --check Read-only mode for CI (no auto-fix)
# --test Also run tests (slower)
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
CHECK_MODE=0
RUN_TESTS=0
for arg in "$@"; do
case "$arg" in
--check) CHECK_MODE=1 ;;
--test) RUN_TESTS=1 ;;
esac
done
BINDINGS="$ROOT_DIR/bindings/python"
PY_SRC="$BINDINGS/python"
YELLOW='\033[0;33m'
# Setup venv (must be sequential)
uv venv --quiet 2>/dev/null || true
source .venv/bin/activate
uv pip install maturin ruff mypy vulture pytest --quiet 2>/dev/null
echo -e "${CYAN}→ maturin develop${NC}"
if ! maturin develop --manifest-path "$BINDINGS/Cargo.toml" > /dev/null 2>&1; then
echo -e "${RED}✗ maturin develop failed${NC}"
exit 1
fi
TMPDIR_LINT=$(mktemp -d)
trap "rm -rf $TMPDIR_LINT" EXIT
FAILED=0
PIDS=()
TASKS=()
run_task() {
local name="$1"
local outfile="$TMPDIR_LINT/$name.out"
shift
TASKS+=("$name")
echo -e "${CYAN}→ $name${NC}"
(
if "$@" > "$outfile" 2>&1; then
echo "0" > "$outfile.status"
else
echo "1" > "$outfile.status"
fi
) &
PIDS+=($!)
}
wait_all() {
local i=0
for pid in "${PIDS[@]}"; do
wait "$pid" || true
local name="${TASKS[$i]}"
local outfile="$TMPDIR_LINT/$name.out"
if [[ -f "$outfile.status" && "$(cat "$outfile.status")" != "0" ]]; then
echo -e "${RED}✗ $name${NC}"
cat "$outfile"
echo ""
FAILED=1
fi
i=$((i + 1))
done
}
if [[ "$CHECK_MODE" -eq 1 ]]; then
run_task "ruff-format" ruff format "$PY_SRC" --check
run_task "ruff-check" ruff check "$PY_SRC"
else
run_task "ruff-format" ruff format "$PY_SRC"
run_task "ruff-check" ruff check "$PY_SRC" --fix
fi
run_task "mypy" mypy "$PY_SRC"
run_task "vulture" vulture "$PY_SRC" --min-confidence 80
if [[ "$RUN_TESTS" -eq 1 ]]; then
run_task "pytest" pytest
fi
wait_all
if [[ "$FAILED" -eq 0 ]]; then
echo -e "${GREEN}✓ All checks passed${NC}"
else
exit 1
fi