Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Current »

Style guides refer to a set of standards for writing and formatting code. Having a consistent style guide makes it much easier to understand a large codebase. We recommend using the following style guides.

Python

Python code should follow Generic coding conventions as specified in the Style Guide for Python Code (PEP 8).

  • 4 spaces per indentation level - no hard tabs.

  • UTF-8 encoding

  • Maximum of 78 characters per line.

Of particular importance should be with with variable naming conventions
https://peps.python.org/pep-0008/#naming-conventions

  • CapWords convention for Class names

  • Use lowercase or lowercase_with_underscores for function, method, and variable names.

    • For short names, joined lowercase may be used (e.g. "tagname"). Choose what is most readable.

  • No single-character variable names, except indices in loops that encompass a very small number of lines

  • Use 'single quotes' for string literals, and """triple double quotes""" for docstrings.

    • Use double quotes for strings when necessary like "don't".

  • When using dataclasses - it should belong to the module using it

Guidelines

When contributing code, you should use a Linter.
A Linter is a tool that performs static source code analysis. The tool can check your code syntax and provide instructions on how to improve it.

For Python, recommend pylint: https://pypi.org/project/pylint/

Flake 8 is another linter: https://flake8.pycqa.org/en/latest/index.html

For Python, code can be automatically formatted to match PEP8 style guide using black: https://black.readthedocs.io/en/stable/

Black is an opinionated code formatter, it can take your Python code and automatically reformat it to adhere to a strict set of style guidelines. Its a good idea to run black just before you commit and push your code to GitHub.

  • No labels