Skip to content

Commit

Permalink
added pep8 git pre commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hager committed Dec 23, 2011
1 parent 6975ca6 commit 7fae3cb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Readme.md
Original file line number Original file line Diff line number Diff line change
@@ -1,16 +1,22 @@
#Boilerplate Collection # Boilerplate Collection


Boilerplates are basic setups with best practices. Just take the parts you like. Boilerplates are basic setups with best practices. Just take the parts you like.


###Python ### Python


* [Python Script](https://github.com/metachris/boilerplates/tree/master/python) * [Python Script](https://github.com/metachris/boilerplates/tree/master/python)
* [Tornado Website](https://github.com/metachris/tornado-boilerplate) * [Tornado Website](https://github.com/metachris/tornado-boilerplate)
* [App Engine Website](https://github.com/metachris/appengine-boilerplate) * [App Engine Website](https://github.com/metachris/appengine-boilerplate)




###Dotfiles ### PEP8 Pre Commit Hook for Git

This [git pre-commit hook](https://github.com/metachris/boilerplates/tree/master/python/pep8-git-pre-commit-hook) checks for pep8 compatibility on committing, and aborts the commit if errors are found. Can be skipped by applying the `--no-verify` flag to `git commit`. This requires the tool `pep8` which can be installed via package managers and homebrew.

To use the commit hook in all projects on this system, copy it into the global git hook-templates directory (eg. `/usr/share/git-core/templates/hooks/`) as a file called `pre-commit` and set the permissions to executable. Afterwards you can enable this hook in existing repositories by calling `git init`. New repositories will use it by default.


[Boilerplate dotfiles](https://github.com/metachris/boilerplates/tree/master/dotfiles) is a collection of command line goodness for OSX and Linux. Includes `.bash_profile`, `.aliases`, `.exports`, and others.


### Dotfiles

[Boilerplate dotfiles](https://github.com/metachris/boilerplates/tree/master/dotfiles) is a collection of command line goodness for OSX and Linux. Includes `.bash_profile`, `.aliases`, `.exports`, and others.


36 changes: 36 additions & 0 deletions python/pep8-git-pre-commit-hook
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
from __future__ import with_statement
import os
import shutil
import subprocess
import sys
import tempfile


def system(*args, **kwargs):
kwargs.setdefault('stdout', subprocess.PIPE)
proc = subprocess.Popen(args, **kwargs)
out, err = proc.communicate()
return out


def main():
files = (file for file in system('git', 'diff', '--name-only', '--staged', '--diff-filter=AM').splitlines() if file.endswith('.py'))

tempdir = tempfile.mkdtemp()
for name in files:
filename = os.path.join(tempdir, name)
filepath = os.path.dirname(filename)
if not os.path.exists(filepath):
os.makedirs(filepath)
with file(filename, 'w') as f:
system('git', 'show', ':' + name, stdout=f)
output = system('pep8', '.', cwd=tempdir)
shutil.rmtree(tempdir)
if output:
print output,
sys.exit(1)


if __name__ == '__main__':
main()

0 comments on commit 7fae3cb

Please sign in to comment.