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

check-added-large-files

Prevent giant files from being committed

check-ast

Simply check whether files parse as valid python

check-builtin-literals

Require literal syntax when initializing empty or zero Python builtin types

check-case-conflict

Check for files with names that would conflict on a case-insensitive filesystem

check-docstring-first

Checks for a common error of placing code before the docstring

check-merge-conflict

Check for files that contain merge conflict strings

check-toml

Attempts to load all TOML files to verify syntax

check-vsc-permalinks

Ensures that links to vcs websites are permalinks

check-yaml

Attempts to load all yaml files to verify syntax

debug-statements

Check for debugger imports and py37+ breakpoint() calls in python source

detect-private-key

Checks for the existence of private keys

end-of-file-fixer

Makes sure files end in a newline and only a newline

Modifies the codes

fix-byte-order-marker

Removes UTF-8 byte order marker

Modifies the codes

name-tests-test

Verifies that test files are named correctly

Minterpy adopts test_*.py filename convention

no-commit-to-branch

Protect specific branches from direct commits

dev and main are protected

trailing-whitespace

Trims trailing whitespaces

Modifies the codes

flake8

A Python linter (static code analyzer)

See the configurations in the setup.cfg under [flake8]

black

A code formatter

Only checks src and tests

black-jupyter

A Jupyter notebook formatter

Only checks docs/how-to and docs/getting-started

mypy

A static type checker

See the configurations in the setup.cfg under [mypy*]

check-manifest

A MANIFEST.in state checker

isort

An import statement sorter

Make sure changes according to the suggestion do not break the code