-
Notifications
You must be signed in to change notification settings - Fork 47
Intro git hooks for typechecking #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
884e548
a35e4e9
705f8c0
8f627f0
8fec115
c6c2d3d
c0dbbf5
f6d41c0
c6c3d7d
52c5173
652a94a
cee5cb8
9afe647
5e8799b
8fd9b43
cb5b274
37e64be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||
| #!/bin/bash | ||||||
|
|
||||||
| # Usage | ||||||
| # To install the typechecking linters, simply run the script in your terminal: | ||||||
|
|
||||||
| # sh | ||||||
| # This will install the linters and set up the pre-commit hook to run them on each changed Python file. | ||||||
| # -o, --post-commit, -p, --pre-commit, default -o post commit install | ||||||
|
|
||||||
| # Requirements | ||||||
| # This script requires the following tools to be installed: | ||||||
|
|
||||||
| # Git | ||||||
| # Black | ||||||
| # Ruff | ||||||
| # Mypy | ||||||
| # Make sure these tools are installed and available in your system's PATH before running the script. | ||||||
|
|
||||||
| # Define the hook script | ||||||
| HOOK_SCRIPT="#!/bin/bash | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same again, sorry, but I put a suggestion in so that you can accept or reject it easily!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also probably EOF this, but if it ain't broke. |
||||||
| # Get the list of changed Python files in the darwin/future folder | ||||||
| FILES=\$(git diff --diff-filter=MA --name-only master | grep 'darwin/future/.*\.py$') | ||||||
| if [ -z \"\$FILES\" ]; then | ||||||
| exit 0 | ||||||
| fi | ||||||
| RED='\033[0;31m' | ||||||
| GREEN='\033[0;32m' | ||||||
| echo Typechecking Hook | ||||||
| echo ---------------------------------------- | ||||||
| echo checking \$FILES | ||||||
| # Run the linters on each changed file | ||||||
| echo -e '\nRunning Black' | ||||||
| echo ---------------------------------------- | ||||||
| BLACK_FAILED=0 | ||||||
| black --check \$FILES || BLACK_FAILED=1 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These could each be like BLACK_FAILED=`black --check \$FILES`and so on, with the same function, but again, if it ain't broke. |
||||||
| echo -e '\nRunning Ruff' | ||||||
| echo ---------------------------------------- | ||||||
| RUFF_FAILED=0 | ||||||
| ruff check \$FILES || RUFF_FAILED=1 | ||||||
| echo -e '\nRunning Mypy' | ||||||
| echo ---------------------------------------- | ||||||
| MYPY_FAILED=0 | ||||||
| mypy \$FILES || MYPY_FAILED=1 | ||||||
| # Check if any linter failed | ||||||
| echo Summary | ||||||
| echo ---------------------------------------- | ||||||
| if [ \$BLACK_FAILED -eq 1 ]; then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider escaped quotes around comparison variables. Prevents them going wrong in certain scenarios. Again, it's a good practice > required. |
||||||
| echo -e \"\${RED}Black failed.\" | ||||||
| fi | ||||||
| if [ \$RUFF_FAILED -eq 1 ]; then | ||||||
| echo -e \"\${RED}Ruff failed.\" | ||||||
| fi | ||||||
| if [ \$MYPY_FAILED -eq 1 ]; then | ||||||
| echo -e \"\${RED}Mypy failed.\" | ||||||
| fi | ||||||
| if [ \$BLACK_FAILED -eq 0 ] && [ \$RUFF_FAILED -eq 0 ] && [ \$MYPY_FAILED -eq 0 ]; then | ||||||
| echo -e \"\${GREEN}All checks passed.\" | ||||||
| fi | ||||||
| " | ||||||
|
|
||||||
| # Define the hook name | ||||||
| HOOK_NAME="linters" | ||||||
|
|
||||||
| # Define the hook directory | ||||||
| HOOK_DIR="$(git rev-parse --show-toplevel)/.git/hooks" | ||||||
|
|
||||||
| # Define the hook file names | ||||||
| PRE_COMMIT_FILE="$HOOK_DIR/pre-commit" | ||||||
| POST_COMMIT_FILE="$HOOK_DIR/post-commit" | ||||||
|
|
||||||
| # Define the hook file names with the hook name | ||||||
| PRE_COMMIT_HOOK_FILE="$HOOK_DIR/pre-commit" | ||||||
| POST_COMMIT_HOOK_FILE="$HOOK_DIR/post-commit" | ||||||
|
|
||||||
| # Define the default hook file name | ||||||
| DEFAULT_HOOK_FILE="$POST_COMMIT_FILE" | ||||||
|
|
||||||
| # Define the default hook type | ||||||
| DEFAULT_HOOK_TYPE="post-commit" | ||||||
|
|
||||||
| # Parse the command line arguments | ||||||
| while [[ $# -gt 0 ]] | ||||||
| do | ||||||
| key="$1" | ||||||
|
|
||||||
| case $key in | ||||||
| -p|--pre-commit) | ||||||
| DEFAULT_HOOK_FILE="$PRE_COMMIT_FILE" | ||||||
| DEFAULT_HOOK_TYPE="pre-commit" | ||||||
| shift | ||||||
| ;; | ||||||
| -o|--post-commit) | ||||||
| DEFAULT_HOOK_FILE="$POST_COMMIT_FILE" | ||||||
| DEFAULT_HOOK_TYPE="post-commit" | ||||||
| shift | ||||||
| ;; | ||||||
| *) | ||||||
| echo "Unknown option: $key" | ||||||
| exit 1 | ||||||
| ;; | ||||||
| esac | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NGL, that's pretty nice |
||||||
| done | ||||||
|
|
||||||
| # Create the hook file | ||||||
| echo "$HOOK_SCRIPT" > "$DEFAULT_HOOK_FILE" | ||||||
|
|
||||||
| # Make the hook file executable | ||||||
| chmod +x "$DEFAULT_HOOK_FILE" | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ def move_items_to_stage( | |
|
|
||
| Returns | ||
| ------- | ||
| None | ||
| JSONType | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the other file change are just two minor changes to test that it was grabbing the right files |
||
| """ | ||
|
|
||
| return api_client.post( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝🏻 better x-plat support on different machines nowadays. More of a good practice thing than anything because who doesn't have bash?