mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 20:44:18 +00:00
Merge 51f8cc8ff0 into 78818b90cd
This commit is contained in:
commit
f8de2e4621
6 changed files with 9 additions and 14 deletions
|
|
@ -2,7 +2,6 @@ from __future__ import absolute_import
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import io
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import autopep8
|
import autopep8
|
||||||
|
|
@ -14,12 +13,12 @@ def main(argv=None):
|
||||||
|
|
||||||
retv = 0
|
retv = 0
|
||||||
for filename in args.files:
|
for filename in args.files:
|
||||||
original_contents = io.open(filename).read()
|
original_contents = open(filename).read()
|
||||||
new_contents = autopep8.fix_code(original_contents, args)
|
new_contents = autopep8.fix_code(original_contents, args)
|
||||||
if original_contents != new_contents:
|
if original_contents != new_contents:
|
||||||
print('Fixing {}'.format(filename))
|
print('Fixing {}'.format(filename))
|
||||||
retv = 1
|
retv = 1
|
||||||
with io.open(filename, 'w') as output_file:
|
with open(filename, 'w') as output_file:
|
||||||
output_file.write(new_contents)
|
output_file.write(new_contents)
|
||||||
|
|
||||||
return retv
|
return retv
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ def main(argv=None):
|
||||||
retv = 0
|
retv = 0
|
||||||
|
|
||||||
for filename in args.filenames:
|
for filename in args.filenames:
|
||||||
contents = io.open(filename).read()
|
contents = open(filename).read()
|
||||||
retv |= check_docstring_first(contents, filename=filename)
|
retv |= check_docstring_first(contents, filename=filename)
|
||||||
|
|
||||||
return retv
|
return retv
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import io
|
|
||||||
import sys
|
import sys
|
||||||
import xml.sax
|
import xml.sax
|
||||||
|
|
||||||
|
|
@ -16,7 +15,7 @@ def check_xml(argv=None):
|
||||||
retval = 0
|
retval = 0
|
||||||
for filename in args.filenames:
|
for filename in args.filenames:
|
||||||
try:
|
try:
|
||||||
with io.open(filename, 'rb') as xml_file:
|
with open(filename, 'rb') as xml_file:
|
||||||
xml.sax.parse(xml_file, xml.sax.ContentHandler())
|
xml.sax.parse(xml_file, xml.sax.ContentHandler())
|
||||||
except xml.sax.SAXException as exc:
|
except xml.sax.SAXException as exc:
|
||||||
print('{}: Failed to xml parse ({})'.format(filename, exc))
|
print('{}: Failed to xml parse ({})'.format(filename, exc))
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ def get_line_offsets_by_line_no(src):
|
||||||
|
|
||||||
|
|
||||||
def fix_strings(filename):
|
def fix_strings(filename):
|
||||||
contents = io.open(filename).read()
|
contents = open(filename).read()
|
||||||
line_offsets = get_line_offsets_by_line_no(contents)
|
line_offsets = get_line_offsets_by_line_no(contents)
|
||||||
|
|
||||||
# Basically a mutable string
|
# Basically a mutable string
|
||||||
|
|
@ -52,7 +52,7 @@ def fix_strings(filename):
|
||||||
|
|
||||||
new_contents = ''.join(splitcontents)
|
new_contents = ''.join(splitcontents)
|
||||||
if contents != new_contents:
|
if contents != new_contents:
|
||||||
with io.open(filename, 'w') as write_handle:
|
with open(filename, 'w') as write_handle:
|
||||||
write_handle.write(new_contents)
|
write_handle.write(new_contents)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import io
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -14,5 +13,5 @@ def get_resource_path(path):
|
||||||
|
|
||||||
def write_file(filename, contents):
|
def write_file(filename, contents):
|
||||||
"""Hax because coveragepy chokes on nested context managers."""
|
"""Hax because coveragepy chokes on nested context managers."""
|
||||||
with io.open(filename, 'w', newline='') as file_obj:
|
with open(filename, 'w', newline='') as file_obj:
|
||||||
file_obj.write(contents)
|
file_obj.write(contents)
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import io
|
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
def test_readme_contains_all_hooks():
|
def test_readme_contains_all_hooks():
|
||||||
readme_contents = io.open('README.md').read()
|
readme_contents = open('README.md').read()
|
||||||
hooks = yaml.load(io.open('hooks.yaml').read())
|
hooks = yaml.load(open('hooks.yaml').read())
|
||||||
for hook in hooks:
|
for hook in hooks:
|
||||||
assert '`{}`'.format(hook['id']) in readme_contents
|
assert '`{}`'.format(hook['id']) in readme_contents
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue