diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1da2b96 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.mypy] +disallow_untyped_defs = true +disallow_any_unimported = true +no_implicit_optional = true +check_untyped_defs = true +warn_return_any = true +warn_unused_ignores = true +show_error_codes = true + +[tool.black] +line-length = 120 + +[tool.isort] +profile = "black" diff --git a/scripts/pre_commit.sh b/scripts/pre_commit.sh new file mode 100755 index 0000000..00eeb6a --- /dev/null +++ b/scripts/pre_commit.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +error=0 + +function run_linter() { + echo -ne "\033[1mRunning $2 ...\033[0m" + output=$($1 2>&1) + result=$? + + if [ $result -eq 0 ]; then + echo -e "\033[1K\r\033[1mRunning $2 ✅\033[0m" + else + echo -e "\033[1K\r\033[1mRunning $2 ❌\033[0m" + echo -e "\n$output" + fi + + ((error+=result)) +} + +run_linter "mypy ." "Running Mypy" +run_linter "black --diff ." "Running Black" +run_linter "isort --check-only --diff ." "Running ISort" + +exit $error diff --git a/scripts/set_git_hooks.sh b/scripts/set_git_hooks.sh new file mode 100755 index 0000000..2091ff4 --- /dev/null +++ b/scripts/set_git_hooks.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +GIT=$(git rev-parse --git-dir) +ln -s ../../scripts/pre_commit.sh $GIT/hooks/pre-commit