Skip to content

Commit 1dd0e50

Browse files
authored
Intro git hooks for typechecking (#689)
* hook installer * hook installer default * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * testing hooks * cleanup
1 parent 21cbfe0 commit 1dd0e50

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

.hooks/typechecking_installer.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
# Usage
4+
# To install the typechecking linters, simply run the script in your terminal:
5+
6+
# sh
7+
# This will install the linters and set up the pre-commit hook to run them on each changed Python file.
8+
# -o, --post-commit, -p, --pre-commit, default -o post commit install
9+
10+
# Requirements
11+
# This script requires the following tools to be installed:
12+
13+
# Git
14+
# Black
15+
# Ruff
16+
# Mypy
17+
# Make sure these tools are installed and available in your system's PATH before running the script.
18+
19+
# Define the hook script
20+
HOOK_SCRIPT="#!/bin/bash
21+
# Get the list of changed Python files in the darwin/future folder
22+
FILES=\$(git diff --diff-filter=MA --name-only master | grep 'darwin/future/.*\.py$')
23+
if [ -z \"\$FILES\" ]; then
24+
exit 0
25+
fi
26+
RED='\033[0;31m'
27+
GREEN='\033[0;32m'
28+
echo Typechecking Hook
29+
echo ----------------------------------------
30+
echo checking \$FILES
31+
# Run the linters on each changed file
32+
echo -e '\nRunning Black'
33+
echo ----------------------------------------
34+
BLACK_FAILED=0
35+
black --check \$FILES || BLACK_FAILED=1
36+
37+
echo -e '\nRunning Ruff'
38+
echo ----------------------------------------
39+
RUFF_FAILED=0
40+
ruff check \$FILES || RUFF_FAILED=1
41+
42+
echo -e '\nRunning Mypy'
43+
echo ----------------------------------------
44+
MYPY_FAILED=0
45+
mypy \$FILES || MYPY_FAILED=1
46+
47+
# Check if any linter failed
48+
echo Summary
49+
echo ----------------------------------------
50+
if [ \$BLACK_FAILED -eq 1 ]; then
51+
echo -e \"\${RED}Black failed.\"
52+
fi
53+
if [ \$RUFF_FAILED -eq 1 ]; then
54+
echo -e \"\${RED}Ruff failed.\"
55+
fi
56+
if [ \$MYPY_FAILED -eq 1 ]; then
57+
echo -e \"\${RED}Mypy failed.\"
58+
fi
59+
if [ \$BLACK_FAILED -eq 0 ] && [ \$RUFF_FAILED -eq 0 ] && [ \$MYPY_FAILED -eq 0 ]; then
60+
echo -e \"\${GREEN}All checks passed.\"
61+
fi
62+
"
63+
64+
# Define the hook name
65+
HOOK_NAME="linters"
66+
67+
# Define the hook directory
68+
HOOK_DIR="$(git rev-parse --show-toplevel)/.git/hooks"
69+
70+
# Define the hook file names
71+
PRE_COMMIT_FILE="$HOOK_DIR/pre-commit"
72+
POST_COMMIT_FILE="$HOOK_DIR/post-commit"
73+
74+
# Define the hook file names with the hook name
75+
PRE_COMMIT_HOOK_FILE="$HOOK_DIR/pre-commit"
76+
POST_COMMIT_HOOK_FILE="$HOOK_DIR/post-commit"
77+
78+
# Define the default hook file name
79+
DEFAULT_HOOK_FILE="$POST_COMMIT_FILE"
80+
81+
# Define the default hook type
82+
DEFAULT_HOOK_TYPE="post-commit"
83+
84+
# Parse the command line arguments
85+
while [[ $# -gt 0 ]]
86+
do
87+
key="$1"
88+
89+
case $key in
90+
-p|--pre-commit)
91+
DEFAULT_HOOK_FILE="$PRE_COMMIT_FILE"
92+
DEFAULT_HOOK_TYPE="pre-commit"
93+
shift
94+
;;
95+
-o|--post-commit)
96+
DEFAULT_HOOK_FILE="$POST_COMMIT_FILE"
97+
DEFAULT_HOOK_TYPE="post-commit"
98+
shift
99+
;;
100+
*)
101+
echo "Unknown option: $key"
102+
exit 1
103+
;;
104+
esac
105+
done
106+
107+
# Create the hook file
108+
echo "$HOOK_SCRIPT" > "$DEFAULT_HOOK_FILE"
109+
110+
# Make the hook file executable
111+
chmod +x "$DEFAULT_HOOK_FILE"

darwin/future/core/items/move_items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def move_items_to_stage(
3131
3232
Returns
3333
-------
34-
None
34+
JSONType
3535
"""
3636

3737
return api_client.post(

darwin/importer/formats/coco.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from upolygon import find_contours, rle_decode
88

99
import darwin.datatypes as dt
10-
from darwin.exceptions import UnrecognizableFileEncoding
1110
from darwin.path_utils import deconstruct_full_path
1211
from darwin.utils import attempt_decode
1312
from darwin.version import __version__

0 commit comments

Comments
 (0)