NLeSC / python-template

Netherlands eScience Center Python Template
https://research-software-directory.org/software/nlesc-python-template
Apache License 2.0
180 stars 76 forks source link

Use library for git pre commit hook #222

Open sverhoeven opened 3 years ago

sverhoeven commented 3 years ago

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.

bouweandela commented 1 year ago

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.

abelsiqueira commented 1 year ago

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.

egpbos commented 9 months ago

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