osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What Python related git pre-commit hooks are you using?


On Mon, Nov 19, 2018 at 6:34 AM Malcolm Greene <python at bdurham.com> wrote:
>
> Curious to learn what Python related git pre-commit hooks people are
> using? What hooks have you found useful and which hooks have you tried
> and abandoned? Appreciate any suggestions for those new to this process.
> Background: Window, macOS, and Linux dev environments, PyCharm professional edition IDE, 64-bit Python 3.6, private Github repos. Considering black (standardize formatting), pylamas (multiple static code tests) and possibly a hook into our pytest test runner.
> Thanks!

Here are a few that I've written and actively use.

This hook isn't written in Python, but I use it with my Python projects:
https://github.com/Rosuav/shed/blob/master/githook.pike
Whenever you make a commit that affects only a single file, it
automatically prepopulates the message with a tag, based on previous
commits affecting that file.

This one is written in Python, but is less for Python projects and
more for my git-managed config directories (like my /etc on most
computers):
https://github.com/Rosuav/shed/blob/master/git-watch
Once configured, it notifies me any time there are uncommitted
changes. For a typical source code repo, that's not particularly
likely, but when the files can be edited by other programs (or by
running system updates), it's good to be told.

Another one written in Python, but not a hook per se:
https://github.com/Rosuav/shed/blob/master/git-triangle
Triangle cloning is a variant of git clone designed for a pull-request model.

And this one is just a convenient tool.
https://github.com/Rosuav/shed/blob/master/git-ignore
Type "git ignore __pycache__" after you notice that you committed a
bunch of pyc files. Adds the line to .gitignore and then removes (from
the repo, but not your disk) every file that ought to be ignored.

Feel free to snag any parts you like, or to use them as inspiration.
The code is all MIT-licensed so have fun.

I'm also interested to see what tools other people use! Thanks for
starting this discussion.

ChrisA