Skip to content

Latest commit

 

History

History
77 lines (45 loc) · 2.44 KB

File metadata and controls

77 lines (45 loc) · 2.44 KB

Python Style Guide

Packaging

See the official Python packaging projects guide to get started.

New projects must use pyproject.toml for project metadata. Do not use setup.py for new packages.

If you cannot run your Python project directly as a module python -m app, it is not packaged correctly.

If you rely on data outside of your package, you must handle considerations for when that data is not present when your package is run. Do not rely on hard coding paths, make them configurable.

Arguments

Do not roll your own options parser. Use argparse from the stdlib.

Python conventions

In general the rules of thumb are:

  • Class names should use UpperCamelCase
  • Constant names should be CAPITALIZED_WITH_UNDERSCORES
  • Other names should use lowercase_separated_by_underscores
  • Private variables/methods should start with an underscore: _myvar
  • Some special class methods are surrounded by two underscores: __init__

In some cases, we break the rules.

CamelCase

When using abbreviations with CamelCase, capitalize all the letters of the abbreviation. For example, Dot11FT is desired rather than Dot11Ft.

Python version guidelines

Python 3.13 is the standard for new development. This aligns with the system Python in Debian Trixie, which is the active development target for WLAN Pi.

Bookworm (Python 3.11) may still receive bug fixes on existing packages. Bullseye (Python 3.9) is end-of-life for WLAN Pi.

Existing repos may still carry older targets such as py39 or py311 in their tox.ini and pyproject.toml. These should be updated to include py313 when the repo is next actively worked on.

Tests

The Python testing framework of choice should be pytest.

Tox for standardized testing, linting, and formatting

To familiarize yourself with tox, read the tox documentation here.

Install tox:

python3 -m pip install tox

You can now invoke tox in the directory where tox.ini resides.

These are some things you should do before submitting a PR:

To initiate testing:

tox

See wlanpi-profiler/tox.ini for an example tox.ini.

Lint your code:

tox -e lint

Format your code:

tox -e format