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 micropython-upip: Mark as binary file and re-commit. 2015-06-06 23:09:23 +03:00
.gitignore tools: check-in errordeveloper/tinytest@eb2dbc858f 2014-05-08 01:41:21 +03:00
bootstrap_upip.sh tools/upip: Upgrade upip to 1.2.4. 2018-04-23 16:11:27 +10:00
build-stm-latest.sh tools: Add STM32F4DISC and ESPRUINO_PICO to stmhal build script. 2015-04-21 13:16:41 +00:00
cc1 tools: Add C middle-processor to make builtin tables proper hash tables. 2015-12-31 00:24:33 +00:00
check_code_size.sh all: Update Makefiles and others to build with new ports/ dir layout. 2017-09-06 14:09:13 +10:00
codeformat.py tools/codeformat.py: Add formatter using uncrustify for C, black for Py. 2020-02-28 10:14:28 +11:00
codestats.sh all: Update Makefiles and others to build with new ports/ dir layout. 2017-09-06 14:09:13 +10:00
dfu.py tools/dfu.py: Pad image data to 8 byte alignment to support L476. 2018-07-20 14:23:11 +10:00
file2h.py tools: Fix up pybcdc.inf generation: new lines and hex digits. 2014-04-16 11:45:52 +01:00
gen-changelog.sh Rename "Micro Python" to "MicroPython" in REPL, help, readme's and misc. 2015-10-12 00:06:25 +01:00
gen-cpydiff.py tools/gen-cpydiff.py: Adjust subsections to sentence case. 2020-01-06 22:16:18 +11:00
gendoc.py tools: Make gendoc.py able to output RST format. 2014-10-31 01:36:11 +00:00
insert-usb-ids.py various: Spelling fixes 2017-05-29 11:36:05 +03:00
make-frozen.py tools/make-frozen.py: Allow to run with no directory passed in. 2019-10-15 21:33:49 +11:00
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 tools/mpy_bin2res: Tools to convert binary resources to Python module. 2017-07-27 14:41:27 +03:00
mpy_cross_all.py tools/mpy_cross_all.py: Helper tool to run mpy-cross on the entire project. 2017-05-14 17:51:12 +03:00
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 tools: Add uf2conv.py from Microsoft/uf2 repository. 2019-07-01 17:18:44 +10:00
uncrustify.cfg tools/codeformat.py: Add formatter using uncrustify for C, black for Py. 2020-02-28 10:14:28 +11:00
upip.py tools/upip.py: Add support for multiple index URLs with custom default. 2019-05-15 15:46:16 +10:00
upip_utarfile.py tools/upip: Upgrade to 1.2.2. 2017-09-29 18:24:11 -07:00