Closed faaxm closed 1 year ago
You could also just use pre-commit
together with the python distribution of clang-format.
This is the easiest way to have a specific version of clang-format run on only matching files cross platform.
Plus you can install the pre-commit hook so it runs before each commit and intercepts it if needed. ^^
@s-weigand Oh, I didn't expect anyone to actually look at my pull request! Thanks for the info! 🙂
Using pre-commit
would mean that anyone contributing to spix would have to have clang-format setup in that way, right? I think for an opensource project, I would like to keep the process as open and flexible as possible, to not add any entry barriers for new contributors.
But maybe would be worth having a note on this somewhere in the readme or additional docs? Will think about it some more...
pre-commit
is a python package and a framework to run QA tools with a specific version based on the git tag of a repository containing the hook configuration.
Each tool gets its own environment so it isn't polluting you system path with those tools (e.g. you could use clang-format
11 on one project and clang-format
16 on another project without them interfering or even knowing about each other).
It supports multiple languages natively (e.g. python
, nodejs
, go
, rust
) and can bootstrap isolated environments for them without the need for a system-wide installation.
The configuration (including which version of a tool to use) is done .pre-commit-config.yaml
which defines the version of a hook, additional dependencies, CLI flags, and which files it should be applied to.
By default pre-commit
only runs the hooks on tracked files with changes, but you can also run it on all tracked files (pre-commit run --all
), so there is no need to manually filter gitignored files (e.g. in the build or dep-libs folders).
Since most of the good tooling for c++ is at least in part written in python (e.g. gcovr or clang-tidy and clang-format) contributor most likely already have python installed so that shouldn't be a barrier.
The goal of clang-format-wheel
is to have an easy way to get clang-format
installed and running cross platform without the need to compile half of the llvm-project.
Installing pre-commit
as a git hook (pre-commit install
) allows you to automatically run all your tools on the staged files of each commit, without the need to think about it ("Did I already run clang-format?") or polluting the commit history with "run clang-format" commits.
It also has a github-action that uses caching out of the box.
I have been using it for a few years now and can't imagine working without it 😅
Different clang-format versions format code differently. This PR makes sure that we default to version 11.