Skip to content

Instantly share code, notes, and snippets.

@davehunt
Forked from lentil/gist:810399
Created August 31, 2012 22:45

Revisions

  1. davehunt revised this gist Aug 31, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pre-commit
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ def main():
    os.makedirs(filepath)
    with file(filename, 'w') as f:
    system('git', 'show', ':' + name, stdout=f)
    output = system('pep8', '.', cwd=tempdir)
    output = system('pep8', '.', '-r', '--ignore=E501', cwd=tempdir)
    shutil.rmtree(tempdir)
    if output:
    print output,
  2. davehunt renamed this gist Aug 31, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @kevinmcconnell kevinmcconnell revised this gist Feb 4, 2011. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,6 @@
    import tempfile


    # to reinit a whole tree do something like:
    # find . -name .git -exec git --git-dir {} init \;


    def system(*args, **kwargs):
    kwargs.setdefault('stdout', subprocess.PIPE)
    proc = subprocess.Popen(args, **kwargs)
  4. @kevinmcconnell kevinmcconnell created this gist Feb 3, 2011.
    43 changes: 43 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/usr/bin/env python
    from __future__ import with_statement
    import os
    import re
    import shutil
    import subprocess
    import sys
    import tempfile


    # to reinit a whole tree do something like:
    # find . -name .git -exec git --git-dir {} init \;


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


    def main():
    modified = re.compile('^[AM]+\s+(?P<name>.*\.py)', re.MULTILINE)
    files = system('git', 'status', '--porcelain')
    files = modified.findall(files)

    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()