10

Are there any premade solutions to enforce good Python standards in Git commit hooks?

Are there way to automamize this process in local checkouts (akin Bazaar where one can push commit hooks to clients)? It should be enough that when you checkout a repo it would come with commit hooks installed, no further work / commands to run.

E.g. if your .py file has a tab the commit would abort and a droid is send to spank the developer.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435

1 Answers1

10

Update 2020:

8 years later, you would use GitHub Actions, like github/super-linter.
I present that approach in "How to set up actions in GitHub for new user?".


Original answer 2012

You could add a service on GitHub side (see "GitHub - All the Hooks", and the existing third-party services).

But you cannot "push a hook" (see "why it is not possible to git add .git/hooks/my-hook" or "Git remote/shared pre-commit hook".

You can version the script which would serve as hook, but each client would still need to activate their pre-commit hook (with a symbolic link pointing to that versioned script).

An example of such a versioned script (for Python standards) would be visible in this blog post, by Lorenzo Bolla, and updated in this GitHub repo.
It is based on PyLint and PyFlake (see also "PyLint, PyChecker or PyFlakes?").


The OP mentions in the comments the package vvv 0.1

A convenience utility for software source code validation and linting

VVV is a tool for easy validation and linting integration for your software project.
With a single command validate all files, no matter in which programming language, in a source tree against a policy you specify in a simple configuration file.
VVV prevents bad stuff to be committed in your software source control or makes cleaning it up easier.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note: PyLint and PyFlake aren't an answer fr your specific Pep8 Python guide style, only an example of how to install and execute a python script in a Git hook. – VonC Mar 21 '12 at 07:43
  • Now here is a simple one command installable tool for this: pypi.python.org/pypi/vvv/ – Mikko Ohtamaa Apr 20 '12 at 16:20
  • @MikkoOhtamaa Interesting I have included it in the answer for more visibility. – VonC Apr 20 '12 at 17:20