mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-22 01:32:11 +08:00
pre-commit: bring back some checks (#33196)
* add this * add this * nice ... * 120 * remove * no remote * 0 * this * no submodules * like this * try this * validate * like this * split * pass files * no par * check exist * no build * fix * 24.04 * default * test failure * continue * actually fail * clean * import * fix * line * mypy * clean * simpler * final * better * final clean * not true old-commit-hash: 30467b44cd82973576c8073136dede6aa2fa60f0
This commit is contained in:
+60
-4
@@ -1,11 +1,67 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
cd $DIR/../
|
||||
|
||||
# TODO: bring back rest of pre-commit checks:
|
||||
# https://github.com/commaai/openpilot/blob/4b11c9e914707df9def598616995be2a5d355a6a/.pre-commit-config.yaml#L2
|
||||
FAILED=0
|
||||
|
||||
ruff check .
|
||||
lint-imports
|
||||
IGNORED_FILES="uv\.lock|docs\/CARS.md"
|
||||
|
||||
function run() {
|
||||
echo -en "$1"
|
||||
|
||||
for ((i=0; i<$((50 - ${#1})); i++)); do
|
||||
echo -n "."
|
||||
done
|
||||
|
||||
shift 1;
|
||||
CMD="$@"
|
||||
|
||||
set +e
|
||||
log="$((eval "$CMD" ) 2>&1)"
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "[${GREEN}✔${NC}]"
|
||||
else
|
||||
echo -e "[${RED}✗${NC}]"
|
||||
echo "$log"
|
||||
FAILED=1
|
||||
fi
|
||||
set -e
|
||||
}
|
||||
|
||||
function run_tests() {
|
||||
ALL_FILES=$(echo "$@" | sed -E "s/$IGNORED_FILES//g")
|
||||
PYTHON_FILES=$(echo "$ALL_FILES" | grep --color=never '.py$' || true)
|
||||
|
||||
if [[ -n "$PYTHON_FILES" ]]; then
|
||||
run "ruff" ruff check $PYTHON_FILES --quiet
|
||||
run "mypy" mypy $PYTHON_FILES
|
||||
run "Import check" lint-imports
|
||||
fi
|
||||
|
||||
if [[ -n "$ALL_FILES" ]]; then
|
||||
run "Codespell" codespell $ALL_FILES
|
||||
run "Large files check" python3 -m pre_commit_hooks.check_added_large_files --enforce-all $ALL_FILES --maxkb=120
|
||||
run "Shebang check" python3 -m pre_commit_hooks.check_shebang_scripts_are_executable $ALL_FILES
|
||||
fi
|
||||
|
||||
return $FAILED
|
||||
}
|
||||
|
||||
if [[ -n $@ ]]; then
|
||||
VALID_FILES=""
|
||||
for f in $@; do
|
||||
if [[ -f "$f" ]]; then
|
||||
VALID_FILES+="$f"$'\n'
|
||||
fi
|
||||
done
|
||||
run_tests "$VALID_FILES"
|
||||
else
|
||||
run_tests "$(git diff --name-only --cached --diff-filter=AM $(git merge-base HEAD master))"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user