Code Style

We attempt to maintain a consistent coding style across projects so contributors do not have to keep dozens of different styles in their head as they move from project to project.


We follow the PEP8 style guide for Python. Projects should make it easy to check new code for PEP8 violations preferably by flake8. It is up to the individual project to choose an enforcement method, but it should be clearly documented and continuous integration tests should ensure code is correctly styled before merging pull requests.

There are a few PEP8 rules which will vary from project to project. For example, the maximum line length might vary. The test suite should enforce this.


Projects should automatically enforce code style. How a project does so is up to the maintainers, but several good options are documented here.


tox-config is an excellent way to test style. flake8 looks in, among other places, tox.ini for its configuration so if you’re already using tox this is a good place to place your configuration. For example, adding the following snippet to your tox.ini file will run flake8 as part of your test suite:

deps =
    flake8 > 3.0
commands =
    python -m flake8 {posargs}

show-source = True
max-line-length = 100
exclude = .git,.tox,dist,*egg
Unit Test

If you’re not using tox, you can add a unit test to your test suite:

"""This module runs flake8 on a subset of the code base"""
import os
import subprocess
import unittest

# Adjust this as necessary to ensure REPO_PATH resolves to the root of your
# repository.
REPO_PATH = os.path.abspath(os.path.dirname(os.path.join(os.path.dirname(__file__), '../')))

class TestStyle(unittest.TestCase):
    """Run flake8 on the repository directory as part of the unit tests."""

    def test_code_with_flake8(self):
        """Assert the code is PEP8-compliant"""

        # enforced_paths = [
        #     'mypackage/pep8subpackage/',
        #     'mypackage/',
        # ]
        # enforced_paths = [os.path.join(REPO_PATH, p) for p in enforced_paths]

        # If your entire codebase is not already PEP8 compliant, you can enforce
        # the style incrementally using ``enforced_paths``.
        # flake8_command = ['flake8', '--max-line-length', '100'] + enforced_paths
        flake8_command = ['flake8', '--max-line-length', '100', REPO_PATH]

        self.assertEqual(, 0)

if __name__ == '__main__':

Auto formatting

The Black tool is an automatic code formatter for Python. From the website:

By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while and you can focus on the content instead.

Your text editor is very likely to have a plugin to run Black on file saving. The documentation has instructions to set it up in Vim and in VS Code (and in Emacs).

You can check that your code is properly formatted according to Black’s settings by adding the following snippet to your tox.ini file:

deps =
commands =
    python -m black --check {posargs:.}

Remember to add format to your Tox envlist.


Javascript files should be formatted using the prettier code formatter. It has support for many editors and can integrate with ESLint to check the code automatically.