This Repo contains some of the standard Pre-Commit checks or Pre-commit hooks, with standard settings for checks to be performed. With pre-commit hooks you can focus on writing the actual code and logical parts of your code, rather than to worry about the coding standard and once you are done with code ,the pre-commit checks will help you to format and style code in compliance to PEP8 rules, making code structure in line with standard practices and helping others understand and use it easily.
Pre-commit checks are checks perfomed automatically when you make a commit, once a commit command is fired the pre-commit hooks will check the staged files for the their compliance with PEP8 standard and black code style, Once the check is run the pre-commmit hooks will modify the files according to PEP8 rules and the modified file will be added to unstaged area, where you can check the changes made by hooks and verify them and then again add and commit them, only commits which pass all the checks will be actually commited to git ,commits which don't pass checks will not be commited.
Install Required packages:
pip install pre-commit
pip install black
pip install flake8
pip install isort
pip install interrogate
Steps to setup:
- Install the required packages
- Download the config files and place them into root directory of project
- add
.
in pre-fix of the config file names by renaming them, ex: renameflake8
to.flake8
, except forpyproject.toml
thepyproject.toml
file will not be renamed. - run
pre-commit install
to install precommit file to git config automatically, you should see outputpre-commit installed at .git/hooks/pre-commit
. - all done, now just commit you code , the pre-commit checks will run automatically to check your code and return results.
Incase your config files don't work,try by moving the .flake8
and pyproject.toml
files to directory in which .git
is stored.
IMP: To skip a particular commit from pre-checks , add --no-verify
to commit,
example: git commit -m 'commit to skip example' --no-verify
Notes:
files that contain this line are skipped: # flake8: noqa
lines that contain a # noqa
comment at the end will not issue warnings.
Other flake8 warnings: https://flake8.pycqa.org/en/2.5.5/warnings.html
To update hooks to latest version: pre-commit autoupdate