mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-03 18:56:54 +00:00
Remove @entry decorator (and misc cleanup)
This commit is contained in:
parent
9bfa01da81
commit
2f1d2bbe5b
13 changed files with 25 additions and 88 deletions
|
|
@ -4,11 +4,8 @@ import argparse
|
|||
import sys
|
||||
import simplejson
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
@entry
|
||||
def check_json(argv):
|
||||
def check_json(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='JSON filenames to check.')
|
||||
args = parser.parse_args(argv)
|
||||
|
|
@ -17,8 +14,8 @@ def check_json(argv):
|
|||
for filename in args.filenames:
|
||||
try:
|
||||
simplejson.load(open(filename))
|
||||
except simplejson.JSONDecodeError as e:
|
||||
print('{0}: Failed to json encode ({1})'.format(filename, e))
|
||||
except simplejson.JSONDecodeError as exc:
|
||||
print('{0}: Failed to json encode ({1})'.format(filename, exc))
|
||||
retval = 1
|
||||
return retval
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@ import argparse
|
|||
import sys
|
||||
import yaml
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
@entry
|
||||
def check_yaml(argv):
|
||||
def check_yaml(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Yaml filenames to check.')
|
||||
args = parser.parse_args(argv)
|
||||
|
|
@ -17,8 +14,8 @@ def check_yaml(argv):
|
|||
for filename in args.filenames:
|
||||
try:
|
||||
yaml.load(open(filename))
|
||||
except yaml.YAMLError as e:
|
||||
print(e)
|
||||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
retval = 1
|
||||
return retval
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ import ast
|
|||
import collections
|
||||
import traceback
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
DEBUG_STATEMENTS = set(['pdb', 'ipdb', 'pudb'])
|
||||
|
||||
|
|
@ -61,8 +59,7 @@ def check_file_for_debug_statements(filename):
|
|||
return 0
|
||||
|
||||
|
||||
@entry
|
||||
def debug_statement_hook(argv):
|
||||
def debug_statement_hook(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to run')
|
||||
args = parser.parse_args(argv)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ import argparse
|
|||
import os
|
||||
import sys
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
def fix_file(file_obj):
|
||||
# Test for newline at end of file
|
||||
|
|
@ -46,8 +44,7 @@ def fix_file(file_obj):
|
|||
return 0
|
||||
|
||||
|
||||
@entry
|
||||
def end_of_file_fixer(argv):
|
||||
def end_of_file_fixer(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||
args = parser.parse_args(argv)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ from __future__ import print_function
|
|||
|
||||
import argparse
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
class Requirement(object):
|
||||
|
||||
|
|
@ -67,8 +65,7 @@ def fix_requirements(f):
|
|||
return 1
|
||||
|
||||
|
||||
@entry
|
||||
def fix_requirements_txt(argv):
|
||||
def fix_requirements_txt(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||
args = parser.parse_args(argv)
|
||||
|
|
@ -76,7 +73,7 @@ def fix_requirements_txt(argv):
|
|||
retv = 0
|
||||
|
||||
for arg in args.filenames:
|
||||
with open(arg, 'rb+') as f:
|
||||
retv |= fix_requirements(f)
|
||||
with open(arg, 'rb+') as file_obj:
|
||||
retv |= fix_requirements(file_obj)
|
||||
|
||||
return retv
|
||||
|
|
|
|||
|
|
@ -2,11 +2,8 @@ from __future__ import print_function
|
|||
|
||||
import sys
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
@entry
|
||||
def validate_files(argv):
|
||||
def validate_files(argv=None):
|
||||
retcode = 0
|
||||
for filename in argv:
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -5,16 +5,13 @@ import fileinput
|
|||
import sys
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit_hooks.util import entry
|
||||
|
||||
|
||||
def _fix_file(filename):
|
||||
for line in fileinput.input([filename], inplace=True):
|
||||
print(line.rstrip())
|
||||
|
||||
|
||||
@entry
|
||||
def fix_trailing_whitespace(argv):
|
||||
def fix_trailing_whitespace(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||
args = parser.parse_args(argv)
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
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