This repo is an example of how to setup a Python project with:
- Pre-commit to ensure that code checks run locally before every commit.
- black to format the codebase and check for code format violations.
- Github Actions to fail the build of PRs introducing code violations.
- Clone this repo.
- Run
pip install requirements/test.txt - Run
pre-commit install
Now, add a Python file with lines longer than 120 chars, using single quotes, etc.
If you try committing it, you'll see an output like this:
$ git commit
black....................................................................Failed
Files were modified by this hook. Additional output:
reformatted test.py
All done! ✨ 🍰 ✨
1 file reformatted.
This repo is also configured to run the code checks via Github Actions. In case a PR author skips the local checks, these actions will make sure that any code violation will cause the build to fail.
The workflow is configured in .github/workflows/checks.yaml.