Pre-Commits#
To adhere to the code standards, you should run numerous checks before committing and submitting the changes for a merge request. To assist you in enforcing code standards, we recommend you to use pre-commit before commiting some changes to your branch.
Note
pre-commit is installed if you follow the instructions on Installing Minterpy for development.
Running and activating pre-commit#
To run all the hooks defined in the .pre-commit-config.yaml
file
against all relevant files, run:
pre-commit run --all-files
If you want to enable pre-commit, execute:
pre-commit install
This command will allow pre-commit
to run against all files
when git commit
is invoked.
If you want to disable the pre-commit script, execute:
pre-commit uninstall
Note
To temporarily disable pre-commit checks when committing for a particular commit, use:
git commit --no-verify
Warning
The Minterpy project utilizes pre-commit hooks, with the required scripts
listed in the .pre-commit-config.yaml
file.
These scripts carry out various checks in your code.
While some hooks may alter the codebase, we restrict the modifications to less-opinionated (and definitely harmless) operations such as eliminating trailing whitespaces. Many of the pre-commit checks do not change the codebase. However, if the checks fail, it is your responsibility to address these issues yourself.
You are encouraged to consider the suggestions provided by the hooks, but always do so with caution. Incorrect implementation may potentially cause the current code to fail.
Even if some changes fail the pre-commit checks, they may still be committed and possibly merged later, provided the test suite passes. In fact, running some pre-commit hooks on the current codebase would definitely fail.
In the future, we aim to comply with a comprehensive set of pre-commit hooks to further enhance the quality and consistency of the codebase.
Currently defined hooks#
The table below summarizes the pre-commit hooks in the Minterpy projects. Unless stated otherwise, the checks do not modify the codebase directly.
Hook |
Description |
Remarks |
---|---|---|
Prevent giant files from being committed |
||
Simply check whether files parse as valid python |
||
Require literal syntax when initializing empty or zero Python builtin types |
||
Check for files with names that would conflict on a case-insensitive filesystem |
||
Checks for a common error of placing code before the docstring |
||
Check for files that contain merge conflict strings |
||
Attempts to load all TOML files to verify syntax |
||
Ensures that links to vcs websites are permalinks |
||
Attempts to load all yaml files to verify syntax |
||
Check for debugger imports and py37+ breakpoint() calls in python source |
||
Checks for the existence of private keys |
||
Makes sure files end in a newline and only a newline |
Modifies the codes |
|
Removes UTF-8 byte order marker |
Modifies the codes |
|
Verifies that test files are named correctly |
Minterpy adopts |
|
Protect specific branches from direct commits |
|
|
Trims trailing whitespaces |
Modifies the codes |
|
A Python linter (static code analyzer) |
See the configurations in the |
|
A code formatter |
Only checks |
|
A Jupyter notebook formatter |
Only checks |
|
A static type checker |
See the configurations in the |
|
A |
||
An import statement sorter |
Make sure changes according to the suggestion do not break the code |