Tools for developers¶
This section presents some useful tools that can be very helpful for the development workflow.
Code linters are tools that analyze source code and identify programming errors, stylistic errors, invalid typing, wrong or missing docstrings, etc.
Linters are often either run directly from the command-line, or they can be run as a part of many modern code editors to give you automatic feedback about your code structure as you write it.
Code stylers are tools that fix styling issues in a file, formatting it automatically. Code styling is different from code linting because it doesn’t change the functionality of your code at all, it only changes how it looks. Using an automatic formatting tool helps to keep the source code within specification and also helps review workflow. While stylers might cause your code to look differently than you would have chosen, many projects have adopted them in order to have a single code style that is consistent across projects.
Currently, black is the most popular code styler for Python.
It will format the code according the
PEP 8 and should work fine with
flake8 (maybe it needs
some extra configuration as, for example,
Git pre-commit hook¶
Git pre-commit hook is a useful tool that checks your code automatically when you run a
git commit and,
if it fails, the
git commit is canceled. This is often used to make sure
that the changes to your code match a particular style, or that there are no
code linting errors.
For example, if you want that
git commit checks if your code matches the PEP8 specification,
you can configure a git flake8 pre-commit hook:
# file: .pre-commit-config.yaml repos: - repo: https://gitlab.com/pycqa/flake8 rev: '3.7.9' hooks: - id: flake8
See the flake8 hooks explanation for more details.
This file specifies a hook that will be triggered automatically before each
in this case, it specifies a flake8 using version
Before you can see any change, first you should install
One way to do it is using
pip install pre-commit # or conda install -c conda-forge pre-commit
Now, you can install your pre-commit hook using
pre-commit install, and it will create the hook based on
git commit command, in this case, git will run
flake8 and, if it fails, the
commit will be canceled.