|
@@ -0,0 +1,41 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+
|
|
|
+import glob
|
|
|
+import os
|
|
|
+import sys
|
|
|
+
|
|
|
+sys.argv = [os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)]
|
|
|
+
|
|
|
+# git usurbs your bin path for hooks and will always run system python
|
|
|
+site_packages = glob.glob('%s/lib/*/site-packages' % os.environ['VIRTUAL_ENV'])[0]
|
|
|
+sys.path.insert(0, site_packages)
|
|
|
+
|
|
|
+def main():
|
|
|
+ """This is the function used by the git hook.
|
|
|
+
|
|
|
+ :param int complexity: (optional), any value > 0 enables complexity
|
|
|
+ checking with mccabe
|
|
|
+ :param bool strict: (optional), if True, this returns the total number of
|
|
|
+ errors which will cause the hook to fail
|
|
|
+ :param str ignore: (optional), a comma-separated list of errors and
|
|
|
+ warnings to ignore
|
|
|
+ :param bool lazy: (optional), allows for the instances where you don't add
|
|
|
+ the files to the index before running a commit, e.g., git commit -a
|
|
|
+ :returns: total number of errors if strict is True, otherwise 0
|
|
|
+ """
|
|
|
+ from flake8.main import DEFAULT_CONFIG
|
|
|
+ from flake8.engine import get_style_guide
|
|
|
+ from flake8.hooks import run
|
|
|
+
|
|
|
+ gitcmd = "git diff-index --cached --name-only HEAD"
|
|
|
+
|
|
|
+ _, files_modified, _ = run(gitcmd)
|
|
|
+ files_modified = filter(lambda x: x.endswith('.py'), files_modified)
|
|
|
+
|
|
|
+ flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
|
|
|
+ report = flake8_style.check_files(files_modified)
|
|
|
+
|
|
|
+ return report.total_errors
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ sys.exit(main())
|