Replies: 2 comments 3 replies
-
|
For typing with mypy, I use a Git pre-commit hook. For what hooks are, see §8.3 Customizing Git - Git Hooks in the (official) Git Book. A web search turns up lots of results for setting up git pre-commit hooks. Here's the contents of the file I have at #!/usr/bin/env python
import sys
import isort.hooks
import mypy.api
# Run isort's built-in git hook and store the error code ("_ec"), if any.
# If this check passes, the result is 0.
isort_ec = isort.hooks.git_hook(strict=True)
# Run mypy through its API, and collect the output and error code
*mypy_output, mypy_ec = mypy.api.run(["--show-error-codes", "--color-output", "."])
if mypy_ec:
# Non-zero → mypy found some errors. Print them.
print(*mypy_output)
# sys.exit(0) tells git that the pre-commit hook was successful.
# If either of the checks failed, the addition of the error codes is non-zero;
# telling git to stop and not finish the commit.
sys.exit(isort_ec + mypy_ec) |
Beta Was this translation helpful? Give feedback.
-
|
An update: currently I use/we recommend using This has the advantage of being more robust than the custom script from my November 2022 comment. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion is for general points about easy ways to follow the code style that applies
ixmp,message_ix,message-ix-models, andmessage_data(private) (but are also good practices to follow in your own code that uses MESSAGEix).For tips that apply in specific editors/IDEs (integrated development environments), see: #672 for VS Code — #675 for Spyper — (others TBA)
Beta Was this translation helpful? Give feedback.
All reactions