micropython/tools
Damien George 4b23e98fb0 tools/codeformat.py: Add formatter using uncrustify for C, black for Py.
This commit adds a tool, codeformat.py, which will reformat C and Python
code to fit a certain style.  By default the tool will reformat (almost)
all the original (ie not 3rd-party) .c, .h and .py files in this
repository.  Passing filenames on the command-line to codeformat.py will
reformat only those.  Reformatting is done in-place.

uncrustify is used for C reformatting, which is available for many
platforms and can be easily built from source, see
https://github.com/uncrustify/uncrustify.  The configuration for uncrustify
is also added in this commit and values are chosen to best match the
existing code style.  A small post-processing stage on .c and .h files is
done by codeformat.py (after running uncrustify) to fix up some minor
items:
- space inserted after * when used as multiplication with sizeof
- #if/ifdef/ifndef/elif/else/endif are dedented by one level when they are
  configuring if-blocks and case-blocks.

For Python code, the formatter used is black, which can be pip-installed;
see https://github.com/psf/black.  The defaults are used, except for line-
length which is set at 99 characters to match the "about 100" line-length
limit used in C code.

The formatting tools used and their configuration were chosen to strike a
balance between keeping existing style and not changing too many lines of
code, and enforcing a relatively strict style (especially for Python code).
This should help to keep the code consistent across everything, and reduce
cognitive load when writing new code to match the style.
2020-02-28 10:14:28 +11:00
..
.gitattributes
.gitignore
bootstrap_upip.sh
build-stm-latest.sh
cc1
check_code_size.sh
codeformat.py tools/codeformat.py: Add formatter using uncrustify for C, black for Py. 2020-02-28 10:14:28 +11:00
codestats.sh
dfu.py
file2h.py
gen-changelog.sh
gen-cpydiff.py tools/gen-cpydiff.py: Adjust subsections to sentence case. 2020-01-06 22:16:18 +11:00
gendoc.py
insert-usb-ids.py
make-frozen.py
makemanifest.py tools/makemanifest.py: Support freezing with empty list of mpy files. 2020-02-20 10:41:50 +11:00
metrics.py tools: Add metrics.py script to build and compute port sizes/metrics. 2020-01-23 12:48:52 +11:00
mpy-tool.py tools/mpy-tool.py: Raise exception if trying to freeze relocatable mpy. 2019-12-12 20:15:28 +11:00
mpy_bin2res.py
mpy_cross_all.py
mpy_ld.py py/persistentcode: Move loading of rodata/bss to before obj/raw-code. 2019-12-17 13:22:11 +11:00
pyboard.py tools/pyboard.py: Change shebang to use python3. 2020-02-01 00:06:26 +11:00
pydfu.py tools/pydfu.py: Clean up syntax, update comments and docstrings. 2020-01-23 13:23:12 +11:00
tinytest-codegen.py tools/tinytest-codegen.py: Add extra newline and result message. 2019-12-19 17:55:50 +11:00
uf2conv.py
uncrustify.cfg tools/codeformat.py: Add formatter using uncrustify for C, black for Py. 2020-02-28 10:14:28 +11:00
upip.py
upip_utarfile.py