first pass at #50 (yapf hook)

This commit is contained in:
jab 2015-03-30 14:46:20 -04:00
parent 15b678e9c6
commit a4dbda57ca
4 changed files with 28 additions and 0 deletions

View file

@ -24,6 +24,8 @@ Add this to your `.pre-commit-config.yaml`
### Hooks available ### 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.) - `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-added-large-files` - Prevent giant files from being committed.
- `check-case-conflict` - Check for files that would conflict in case-insensitive filesystems. - `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. - `check-docstring-first` - Checks a common error of defining a docstring after code.

View file

@ -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 - id: autopep8-wrapper
name: 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.)" description: "Runs autopep8 over python source. (You'll want args: [-i] when using this hook, see .pre-commit-config.yaml for an example.)"

View file

@ -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())

View file

@ -33,9 +33,11 @@ setup(
'pyflakes', 'pyflakes',
'pyyaml', 'pyyaml',
'simplejson', 'simplejson',
# TODO: include yapf when it is released
], ],
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'yapf-wrapper = pre_commit_hooks.yapf_wrapper:main',
'autopep8-wrapper = pre_commit_hooks.autopep8_wrapper:main', 'autopep8-wrapper = pre_commit_hooks.autopep8_wrapper:main',
'check-added-large-files = pre_commit_hooks.check_added_large_files:main', 'check-added-large-files = pre_commit_hooks.check_added_large_files:main',
'check-case-conflict = pre_commit_hooks.check_case_conflict:main', 'check-case-conflict = pre_commit_hooks.check_case_conflict:main',