Commits

markant committed 90bf91b

initial import

Comments (0)

Files changed (4)

+from pep8 import *
+

__init__.pyc

Binary file added.
+#!/usr/bin/python
+from subprocess import Popen, PIPE, STDOUT
+import sys
+
+
+def get_command_output(cmd):
+    """
+    Captures and returns the output of cmd passed in
+    """
+    return Popen(cmd.split(), stdout=PIPE, stderr=STDOUT).communicate()[0]
+
+
+def pep8(ui, repo, **kwargs):
+    """
+    Validates the file against the PEP8 guideslines
+    See http://www.python.org/dev/peps/pep-0008/
+    """
+    changes = repo.status()
+    modified = changes[0]
+    added = changes[1]
+    files = added + modified
+    errors = []
+    for pyfile in files:
+        if pyfile[-2:] != 'py':
+            continue
+        output = get_command_output("/usr/local/bin/pep8 %s" % (pyfile, ))
+        if output:
+            for error in output.split("\n")[:-1]:
+                errors.append(error)
+    if errors:
+        sys.stderr.write("The following files are not PEP8 compliant:\n")
+        sys.stderr.write("\n".join(errors))
+        sys.stderr.write("\n")
+        return -1
+    return 0

pep8.pyc

Binary file added.