Add linting pre-commit hook and hook install script #86

Merged
merenber merged 6 commits from feature-80 into master 2023-05-29 00:14:06 -04:00
3 changed files with 27 additions and 0 deletions

5
.githooks/pre-commit Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
docker run --rm -v "$PWD:$PWD:z" -w "$PWD" python:3.9-bullseye sh -c './lint-docker.sh'
j24chung marked this conversation as resolved Outdated

That regex looks wrong to me - that will also match files which end with ".p" as well as "xp" (since the "." is a wildcard). I think maybe you want e.g. grep '\.py$'.

That regex looks wrong to me - that will also match files which end with ".p" as well as "xp" (since the "." is a wildcard). I think maybe you want e.g. `grep '\.py$'`.

Actually, we can get rid of the STAGED_FILES variable altogether if we just invoke flake8 with no arguments - see comment below.

Actually, we can get rid of the STAGED_FILES variable altogether if we just invoke flake8 with no arguments - see comment below.
exit $?

4
git-hook-install.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# Install pre-configured git hooks
git config --local core.hooksPath .githooks/

18
lint-docker.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
. venv/bin/activate
echo -e "\nLinting Python files with Flake8:\n"
flake8
PASS=$?
echo -e "\nPython linting complete!\n"
if [ "$PASS" -eq 0 ]; then
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
j24chung marked this conversation as resolved Outdated

I think this was mentioned before but in case it wasn't - why are we linting each file individually? flake8 can just be run with no arguments from the root directory, and it will be faster than creating a new process for each file.

I think this was mentioned before but in case it wasn't - why are we linting each file individually? flake8 can just be run with no arguments from the root directory, and it will be faster than creating a new process for each file.

My oriignal thought before was we'd just lint the files that's being modified but rethinking about it, there shouldn't it be a problem with just relinting everything which is easier

My oriignal thought before was we'd just lint the files that's being modified but rethinking about it, there shouldn't it be a problem with just relinting everything which is easier
exit $?
else
echo -e "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass flake8 but do not. Please fix the flake8 errors and try again.\n"
exit 1
fi