From 1622fbe28e16c1c3692e86702be9a14b8d9cb07c Mon Sep 17 00:00:00 2001 From: xxc Date: Wed, 12 Dec 2018 15:48:38 +0800 Subject: [PATCH] add a encoding optional for read python code --- pre_commit_hooks/check_docstring_first.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/check_docstring_first.py b/pre_commit_hooks/check_docstring_first.py index 9988378..29ad193 100644 --- a/pre_commit_hooks/check_docstring_first.py +++ b/pre_commit_hooks/check_docstring_first.py @@ -53,12 +53,13 @@ def check_docstring_first(src, filename=''): def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('filenames', nargs='*') + parser.add_argument('--encoding', default='UTF-8') args = parser.parse_args(argv) retv = 0 for filename in args.filenames: - with io.open(filename, encoding='UTF-8') as f: + with io.open(filename, encoding=args.encoding) as f: contents = f.read() retv |= check_docstring_first(contents, filename=filename)