mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 11:16:53 +00:00
Refactored how entry points work.
This commit is contained in:
parent
5db7f2d807
commit
45741545dc
8 changed files with 71 additions and 42 deletions
|
|
@ -4,6 +4,8 @@ import ast
|
|||
import collections
|
||||
import sys
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
DEBUG_STATEMENTS = set(['pdb', 'ipdb', 'pudb'])
|
||||
|
||||
|
|
@ -43,6 +45,7 @@ def check_file_for_debug_statements(filename):
|
|||
return 0
|
||||
|
||||
|
||||
@entry
|
||||
def debug_statement_hook(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to run')
|
||||
|
|
@ -55,9 +58,5 @@ def debug_statement_hook(argv):
|
|||
return retv
|
||||
|
||||
|
||||
def entry():
|
||||
return debug_statement_hook(sys.argv[1:])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(entry())
|
||||
sys.exit(debug_statement_hook())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ from __future__ import print_function
|
|||
|
||||
import sys
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
@entry
|
||||
def validate_files(argv):
|
||||
retcode = 0
|
||||
for filename in argv:
|
||||
|
|
@ -18,9 +21,5 @@ def validate_files(argv):
|
|||
return retcode
|
||||
|
||||
|
||||
def entry():
|
||||
return validate_files(sys.argv[1:])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(entry())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ import argparse
|
|||
import sys
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
@entry
|
||||
def fix_trailing_whitespace(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||
|
|
@ -22,9 +25,5 @@ def fix_trailing_whitespace(argv):
|
|||
return 0
|
||||
|
||||
|
||||
def entry():
|
||||
fix_trailing_whitespace(sys.argv[1:])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(entry())
|
||||
sys.exit(fix_trailing_whitespace())
|
||||
|
|
|
|||
16
pre_commit_hooks/util.py
Normal file
16
pre_commit_hooks/util.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
import functools
|
||||
import sys
|
||||
|
||||
|
||||
def entry(func):
|
||||
"""Allows a function that has `argv` as an argument to be used as a
|
||||
commandline entry. This will make the function callable using either
|
||||
explicitly passed argv or defaulting to sys.argv[1:]
|
||||
"""
|
||||
@functools.wraps(func)
|
||||
def wrapper(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv[1:]
|
||||
return func(argv)
|
||||
return wrapper
|
||||
Loading…
Add table
Add a link
Reference in a new issue