Code Style
To standardize the code included in this post-processing repository, it is run through automatic formatters and linters.
Warning
For software quality assurance, formatting and linting checks are automatically run on all Pull Requests (and commits) to the Main branch of the repository. When developing this code and submitting a Pull Request, please run all the formatters and linters locally to ensure the code is properly formatted. If the code is not properly formatted, the Pull Request checks will fail.
Python Code
black
black is an automatic formatting tool that will reformat any Python file on which it is called.
The tool is available on PyPI and can be installed using PIP:
pip3 install black
For this repository, black is run using its default configuration, apart from the line length option that is set to 120 characters using the -l flag:
black -l 120 .
This command should be executed in the root directory and should apply to all of the Python code in the repository.
Note
If there is a scenario in which black formatting should not be applied to a block of code, the block can be wrapped in the # fmt: off and # fmt: on directives.
This block will not be affected by black.
flake8
flake8 is a linting tool that will identify issues in Python code and write them to the terminal without modifying the file.
flake8 is often more strict than black and helps ensure that all the Python code within this repository is up to the correct standard.
The tool is available on PyPI and can be installed using PIP:
pip3 install flake8
flake8 can be run with a configuration file that specifies a variety of options.
The configuration file for this repository is included in the root directory with the following configuration options:
[flake8]
ignore = E203, E266, E501, W503, W605, E302, E722
max-line-length = 120
select = B,C,E,F,W,T4,B9
exclude =
# No need to traverse the git directory
.git,
# There's no value in checking cache directories
__pycache__,
# The conf file is mostly autogenerated, ignore it
doc/conf.py,
# No need for init and setup files
*__init__.py
To run flake8, navigate to the root directory and execute the following command:
flake8 .
This command outputs all of the linting errors to the terminal.
Note
If there is a scenario in which flake8 should ignore a specific linting error, the error tag can be added using the inline comment # NOQA: <error tag>.
If the error is general and must be repeatedly ignored, the tag to be ignored can be added to the flake8 configuration file in root directory.