Skip to content

Commit

Permalink
CODECONVENTIONS: Update for change from black to ruff format.
Browse files Browse the repository at this point in the history
Also add notes on running pre-commit manually.

Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
andrewleech authored and dpgeorge committed Nov 9, 2023
1 parent 26d5032 commit 4679a90
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions CODECONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ are then certifying and signing off against the following:
Code auto-formatting
====================

Both C and Python code are auto-formatted using the `tools/codeformat.py`
script. This uses [uncrustify](https://github.com/uncrustify/uncrustify) to
format C code and [black](https://github.com/psf/black) to format Python code.
After making changes, and before committing, run this tool to reformat your
changes to the correct style. Without arguments this tool will reformat all
source code (and may take some time to run). Otherwise pass as arguments to
the tool the files that changed and it will only reformat those.
Both C and Python code formatting are controlled for consistency across the
MicroPython codebase. C code is formatted using the `tools/codeformat.py`
script which uses [uncrustify](https://github.com/uncrustify/uncrustify).
Python code is linted and formatted using
[ruff & ruff format](https://github.com/astral-sh/ruff).
After making changes, and before committing, run `tools/codeformat.py` to
reformat your C code and `ruff format` for any Python code. Without
arguments this tool will reformat all source code (and may take some time
to run). Otherwise pass as arguments to the tool the files that changed,
and it will only reformat those.

uncrustify
==========
Expand Down Expand Up @@ -151,12 +154,22 @@ Tips:
* To ignore the pre-commit message format check temporarily, start the commit
message subject line with "WIP" (for "Work In Progress").

Running pre-commit manually
===========================

Once pre-commit is installed as per the previous section it can be manually
run against the MicroPython python codebase to update file formatting on
demand, with either:
* `pre-commit run --all-files` to fix all files in the MicroPython codebase
* `pre-commit run --file ./path/to/my/file` to fix just one file
* `pre-commit run --file ./path/to/my/folder/*` to fix just one folder

Python code conventions
=======================

Python code follows [PEP 8](https://legacy.python.org/dev/peps/pep-0008/) and
is auto-formatted using [black](https://github.com/psf/black) with a line-length
of 99 characters.
is auto-formatted using [ruff format](https://docs.astral.sh/ruff/formatter)
with a line-length of 99 characters.

Naming conventions:
- Module names are short and all lowercase; eg pyb, stm.
Expand Down

0 comments on commit 4679a90

Please sign in to comment.