mirror of
https://github.com/mandiant/capa.git
synced 2025-12-06 04:41:00 -08:00
hooks: update style checkers in hooks
Run `isort` and `black` in the hooks. Run them with the `--check` option to not modify files which could be committed by accident. Note that the changes in `.gitignore` are not needed as `.log` is already excluded in the Django's section. We add those file to this section in case `.log` is removed in the future.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -111,5 +111,6 @@ venv.bak/
|
||||
!rules/lib
|
||||
|
||||
# hooks output
|
||||
style-checker-output.log
|
||||
isort-output.log
|
||||
black-output.log
|
||||
rule-linter-output.log
|
||||
|
||||
@@ -19,19 +19,37 @@ if [[ "$STASH_LIST" == *"$MSG"* ]]; then
|
||||
echo "Uncommited changes stashed with message '$MSG', if you abort before they are restored run \`git stash pop\`";
|
||||
fi
|
||||
|
||||
# Run style checker and print state (it doesn't block the commit)
|
||||
pycodestyle --config=./.github/tox.ini ./capa/ > style-checker-output.log 2>&1;
|
||||
python_3() {
|
||||
case "$(uname -s)" in
|
||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
||||
py -3 -m $1 > $2 2>&1;;
|
||||
*)
|
||||
python3 -m $1 > $2 2>&1;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run isort and print state (it doesn't block the commit)
|
||||
python_3 'isort --profile black --length-sort --line-width 120 -c .' 'isort-output.log';
|
||||
if [ $? == 0 ]; then
|
||||
echo 'Style checker succeeds!! 💘';
|
||||
echo 'isort succeeded!! 💖';
|
||||
else
|
||||
echo 'Style checker failed 😭';
|
||||
echo 'Check style-checker-output.log for details';
|
||||
echo 'isort failed 😭';
|
||||
echo 'Check isort-output.log for details';
|
||||
fi
|
||||
|
||||
# Run black and print state (it doesn't block the commit)
|
||||
python_3 'black -l 120 --check .' 'black-output.log';
|
||||
if [ $? == 0 ]; then
|
||||
echo 'black succeeded!! 💝';
|
||||
else
|
||||
echo 'black failed 😭';
|
||||
echo 'Check black-output.log for details';
|
||||
fi
|
||||
|
||||
# Run rule linter and print state (it doesn't block the commit)
|
||||
python ./scripts/lint.py ./rules/ > rule-linter-output.log 2>&1;
|
||||
if [ $? == 0 ]; then
|
||||
echo 'Rule linter succeeds!! 💖';
|
||||
echo 'Rule linter succeeded!! 💘';
|
||||
else
|
||||
echo 'Rule linter failed 😭';
|
||||
echo 'Check rule-linter-output.log for details';
|
||||
|
||||
@@ -26,26 +26,46 @@ restore_stashed() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Run style checker and print state
|
||||
pycodestyle --config=./.github/tox.ini ./capa/ > style-checker-output.log 2>&1;
|
||||
python_3() {
|
||||
case "$(uname -s)" in
|
||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
||||
py -3 -m $1 > $2 2>&1;;
|
||||
*)
|
||||
python3 -m $1 > $2 2>&1;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run isort and print state
|
||||
python_3 'isort --profile black --length-sort --line-width 120 -c .' 'isort-output.log';
|
||||
if [ $? == 0 ]; then
|
||||
echo 'Style checker succeeds!! 💘';
|
||||
echo 'isort succeeded!! 💖';
|
||||
else
|
||||
echo 'Style checker failed 😭 PUSH ABORTED';
|
||||
echo 'Check style-checker-output.log for details';
|
||||
echo 'isort failed 😭';
|
||||
echo 'Check isort-output.log for details';
|
||||
restore_stashed;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# Run black and print state
|
||||
python_3 'black -l 120 --check .' 'black-output.log';
|
||||
if [ $? == 0 ]; then
|
||||
echo 'black succeeded!! 💝';
|
||||
else
|
||||
echo 'black failed 😭';
|
||||
echo 'Check black-output.log for details';
|
||||
restore_stashed;
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
# Run rule linter and print state
|
||||
python ./scripts/lint.py ./rules/ > rule-linter-output.log 2>&1;
|
||||
if [ $? == 0 ]; then
|
||||
echo 'Rule linter succeeds!! 💖';
|
||||
echo 'Rule linter succeeded!! 💘';
|
||||
else
|
||||
echo 'Rule linter failed 😭 PUSH ABORTED';
|
||||
echo 'Rule linter failed 😭';
|
||||
echo 'Check rule-linter-output.log for details';
|
||||
restore_stashed;
|
||||
exit 2;
|
||||
exit 3;
|
||||
fi
|
||||
|
||||
# Run tests
|
||||
@@ -57,7 +77,7 @@ else
|
||||
echo 'Tests failed 😓 PUSH ABORTED';
|
||||
echo 'Run `pytest -v --cov=capa test/` if you need more details';
|
||||
restore_stashed;
|
||||
exit 3;
|
||||
exit 4;
|
||||
fi
|
||||
|
||||
echo 'PUSH SUCCEEDED 🎉🎉';
|
||||
|
||||
Reference in New Issue
Block a user