Skip to content

Commit

Permalink
Add git hooks and setup (#2188)
Browse files Browse the repository at this point in the history
Automatically `cargo clippy` and others before you commit
  • Loading branch information
ethanuppal committed Jul 3, 2024
1 parent 4e69a9a commit f59b893
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#/bin/sh

function check {
prog=$1
shift
"$prog" "$@"
if [ $? -ne 0 ]; then
exit 1
fi
}

check cargo clippy

staged_py_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')

if [ -n "$staged_py_files" ]; then
flake8_executable=$(which flake8 || which flake)
if [ -z "$flake8_executable" ]; then
echo "flake is not installed"
exit 1
else
check "$flake8_executable" $staged_py_files
fi
fi
5 changes: 5 additions & 0 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ cargo build # Builds the compiler
./target/debug/calyx --help # Executes the compiler binary
```

We recommend installing the git hooks to run linting and formatting checks before each commit:
```shell
/bin/sh setup_hooks.sh
```

## Running Core Tests

The core test suite tests the Calyx compiler's various passes.
Expand Down
7 changes: 7 additions & 0 deletions setup_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#/bin/sh

for hook in .hooks/*; do
hook_name=$(basename "$hook")
cp "$hook" ".git/hooks/$hook_name" && chmod +x ".git/hooks/$hook_name"
done
echo "Done"

0 comments on commit f59b893

Please sign in to comment.