Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing PEP-8'ish formatting in Github commits

Tags:

git

python

github

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.

like image 593
Mikko Ohtamaa Avatar asked Mar 21 '12 05:03

Mikko Ohtamaa


1 Answers

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.

like image 112
VonC Avatar answered Oct 22 '22 00:10

VonC