From 5cdfe715364844ad783d4ad63394099b7dc33109 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 25 Jul 2023 12:37:06 +1000 Subject: [PATCH] top: Add pre-commit config. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- .pre-commit-config.yaml | 11 +++++++++++ CONTRIBUTING.md | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..e017b86 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: local + hooks: + - id: codeformat + name: MicroPython codeformat.py for changed files + entry: tools/codeformat.py -v -f + language: python + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.280 + hooks: + - id: ruff diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 804a26b..d590754 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,11 +25,21 @@ or packages from micropython-lib, please post at the ### Pull requests The same rules for commit messages, signing-off commits, and commit structure -apply as for the main MicroPython repository. All Python code is formatted -using `black`. See [`tools/codeformat.py`](tools/codeformat.py) to apply -`black` automatically before submitting a PR. +apply [as for the main MicroPython repository](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md). -There are some specific conventions and guidelines for micropython-lib: +All Python code is formatted using the [black](https://github.com/psf/black) +tool. You can run [`tools/codeformat.py`](tools/codeformat.py) to apply +`black` automatically before submitting a PR. The GitHub CI will also run the +[ruff](https://github.com/astral-sh/ruff) tool to apply further "linting" +checks. + +Similar to the main repository, a configuration is provided for the +[pre-commit](https://pre-commit.com/) tool to apply `black` code formatting +rules and run `ruff` automatically. See the documentation for using pre-commit +in [the code conventions document](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md#automatic-pre-commit-hooks) + +In addition to the conventions from the main repository, there are some +specific conventions and guidelines for micropython-lib: * The first line of the commit message should start with the name of the package, followed by a short description of the commit. Package names are