From a4dbda57ca84ba4f89d65779d8235cd242a2f68e Mon Sep 17 00:00:00 2001 From: jab Date: Mon, 30 Mar 2015 14:46:20 -0400 Subject: [PATCH] first pass at #50 (yapf hook) --- README.md | 2 ++ hooks.yaml | 7 +++++++ pre_commit_hooks/yapf_wrapper.py | 17 +++++++++++++++++ setup.py | 2 ++ 4 files changed, 28 insertions(+) create mode 100644 pre_commit_hooks/yapf_wrapper.py diff --git a/README.md b/README.md index b4c7ee8..0dd8998 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Add this to your `.pre-commit-config.yaml` ### Hooks available - `autopep8-wrapper` - Runs autopep8 over python source. (You'll want `args: ['-i]` when using this hook, see `.pre-commit-config.yaml` for an example.) +- `yapf-wrapper` - Runs yapf over python source. (You'll want `args: ['-i]` when using this hook, see `.pre-commit-config.yaml` for an example.) + **NOTE: yapf is currently alpha and has not yet been released, so enabling this hook currently requires you to install yapf manually from source.** - `check-added-large-files` - Prevent giant files from being committed. - `check-case-conflict` - Check for files that would conflict in case-insensitive filesystems. - `check-docstring-first` - Checks a common error of defining a docstring after code. diff --git a/hooks.yaml b/hooks.yaml index 595637f..5cff580 100644 --- a/hooks.yaml +++ b/hooks.yaml @@ -1,3 +1,10 @@ +- id: yapf-wrapper + name: yapf wrapper + description: "Runs yapf over python source. (You'll want args: [-i] when using this hook, see .pre-commit-config.yaml for an example.)" + entry: yapf-wrapper + language: python + files: \.py$ + args: [-i] - id: autopep8-wrapper name: autopep8 wrapper description: "Runs autopep8 over python source. (You'll want args: [-i] when using this hook, see .pre-commit-config.yaml for an example.)" diff --git a/pre_commit_hooks/yapf_wrapper.py b/pre_commit_hooks/yapf_wrapper.py new file mode 100644 index 0000000..89aea41 --- /dev/null +++ b/pre_commit_hooks/yapf_wrapper.py @@ -0,0 +1,17 @@ +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +import io +import sys + +import yapf + + +def main(argv=None): + argv = argv if argv is not None else sys.argv[1:] + return yapf.main(argv) + + +if __name__ == '__main__': + exit(main()) diff --git a/setup.py b/setup.py index 0b3ed31..5b230cd 100644 --- a/setup.py +++ b/setup.py @@ -33,9 +33,11 @@ setup( 'pyflakes', 'pyyaml', 'simplejson', + # TODO: include yapf when it is released ], entry_points={ 'console_scripts': [ + 'yapf-wrapper = pre_commit_hooks.yapf_wrapper:main', 'autopep8-wrapper = pre_commit_hooks.autopep8_wrapper:main', 'check-added-large-files = pre_commit_hooks.check_added_large_files:main', 'check-case-conflict = pre_commit_hooks.check_case_conflict:main',