Commits

Anonymous committed 1958537

pep257 support

Comments (0)

Files changed (1)

 except ImportError:
     HAS_JSLINT = False
 
+try:
+    import pep257
+    HAS_PEP257 = True
+except ImportError:
+    HAS_PEP257 = False
+
+
 from hghooks import CheckerManager, re_options
 
 
     checker_manager = CheckerManager(ui, repo, node, 'no-jslint',
                                      extension='.js')
     return checker_manager.check(jslint_checker)
+
+
+def pep257_check(data, filename):
+    output = pep257.check_source(data, filename)
+    if len(output) > 0:
+        print >> sys.stderr, '\n'.join([str(out) for out in output])
+        return 1
+    return 0
+
+
+def pep257_checker(files_to_check, msg):
+    return sum([pep257_check(data, filename)
+                for filename, data in files_to_check.items()])
+
+
+def pep257hook(ui, repo, hooktype, node, pending, **kwargs):
+    if not HAS_PEP257:
+        ui.warn('You need the pep257 python module to use the pep257hook')
+        return True  # Failure
+
+    checker_manager = CheckerManager(ui, repo, node, 'no-pep257',
+                                     extension='.py')
+    return checker_manager.check(pep257_checker)