python-template icon indicating copy to clipboard operation
python-template copied to clipboard

Use library for git pre commit hook

Open sverhoeven opened this issue 3 years ago • 3 comments

Currently we can use a git hook on pre commit to check style and import order with https://github.com/NLeSC/python-template/blob/c19f866479cd94abcb0151e6f9bc7c55e898b8bc/%7B%7Bcookiecutter.project_name%7D%7D/.githooks/pre-commit#L1 This is a handcrafted script which could be replaced with the https://pre-commit.com/ library. Switching to pre-commit.com would gives us a declarative approach (config file), which to me is better then a imperative program (shell script). Also the many available plugins would make it easier for developers of the project to extend what happens in the hook.

The shell script was added for #82, to get basic git hook.

sverhoeven avatar Apr 22 '21 06:04 sverhoeven

And recommend using pre-commit CI? It's nice, but all people working on the project need to know git reasonably well because it pushes changes to a branch you're working on, so everyone in the project needs to be happy about fixing the occasional merge conflict.

bouweandela avatar Feb 14 '23 12:02 bouweandela

Seconding this. After using pre-commit for a few projects, including a Julia project, it is much easier to maintain and contains many useful hooks that are also useful as the default linter.

We can drop some explicit package requirements and use pre-commit instead.

It is also much easier to add zero-conf or low-conf hooks since you just have to change a few lines in the .pre-commit-hook.yaml. So adding linters and formatters for markdown, yaml, json, and even CITATION.cff is much easier.

For the CI, we can run pre-commit run -a to run all linters and formatters which will also decrease the number of actions.

I wouldn't recommend the pre-commit CI, that can be left to the discretion of the repo owner.

abelsiqueira avatar Sep 08 '23 09:09 abelsiqueira

Following #336, it would be nice if this config adds some good default choices, like ruff format and black.

egpbos avatar Dec 20 '23 16:12 egpbos