From 9f6ad08c505269de79e085c7bdddbe111459fa45 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Wed, 18 Jan 2017 14:16:31 -0800 Subject: [PATCH] Updating hooks. (#660) --- docs/developer/index.rst | 6 ++++++ hooks/pre-commit | 45 ---------------------------------------- 2 files changed, 6 insertions(+), 45 deletions(-) delete mode 100755 hooks/pre-commit diff --git a/docs/developer/index.rst b/docs/developer/index.rst index 69d1e5d0..c6c04f59 100644 --- a/docs/developer/index.rst +++ b/docs/developer/index.rst @@ -113,6 +113,12 @@ HTML: 2 Spaces +Git hooks +~~~~~~~~~ + +To help developers maintain the above standards, Lemur includes a configuration file for Yelp's `pre-commit `_. This is an optional dependency and is not required in order to contribute to Lemur. + + Running the Test Suite ---------------------- diff --git a/hooks/pre-commit b/hooks/pre-commit deleted file mode 100755 index 55645459..00000000 --- a/hooks/pre-commit +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python - -import glob -import os -import sys - -os.environ['PYFLAKES_NODOCTEST'] = '1' - -# pep8.py uses sys.argv to find setup.cfg -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 -if 'VIRTUAL_ENV' in os.environ: - site_packages = glob.glob( - '%s/lib/*/site-packages' % os.environ['VIRTUAL_ENV'])[0] - sys.path.insert(0, site_packages) - - -def py_lint(files_modified): - from flake8.engine import get_style_guide - - # remove non-py files and files which no longer exist - files_modified = filter(lambda x: x.endswith('.py'), files_modified) - - flake8_style = get_style_guide(parse_argv=True) - report = flake8_style.check_files(files_modified) - - return report.total_errors != 0 - - -def main(): - from flake8.hooks import run - - gitcmd = "git diff-index --cached --name-only HEAD" - - _, files_modified, _ = run(gitcmd) - - files_modified = filter(lambda x: os.path.exists(x), files_modified) - - if py_lint(files_modified): - return 1 - return 0 - -if __name__ == '__main__': - sys.exit(main()) \ No newline at end of file