mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 12:34:17 +00:00
Merge pull request #279 from nvtkaszpir/fix/non-utf8-opens
Open files as UTF-8
This commit is contained in:
commit
588232e381
6 changed files with 10 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -12,3 +12,5 @@
|
||||||
/venv*
|
/venv*
|
||||||
coverage-html
|
coverage-html
|
||||||
dist
|
dist
|
||||||
|
# SublimeText project/workspace files
|
||||||
|
*.sublime-*
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,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 = io.open(filename, encoding='UTF-8').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 io.open(filename, 'w', encoding='UTF-8') as output_file:
|
||||||
output_file.write(new_contents)
|
output_file.write(new_contents)
|
||||||
|
|
||||||
return retv
|
return retv
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,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 = io.open(filename, encoding='UTF-8').read()
|
||||||
retv |= check_docstring_first(contents, filename=filename)
|
retv |= check_docstring_first(contents, filename=filename)
|
||||||
|
|
||||||
return retv
|
return retv
|
||||||
|
|
|
||||||
|
|
@ -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 = io.open(filename, encoding='UTF-8').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 io.open(filename, 'w', encoding='UTF-8') as write_handle:
|
||||||
write_handle.write(new_contents)
|
write_handle.write(new_contents)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,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 io.open(filename, 'w', encoding='UTF-8', newline='') as file_obj:
|
||||||
file_obj.write(contents)
|
file_obj.write(contents)
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ def _assert_parseable_in_old_pre_commit(hooks):
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_hooks():
|
def test_legacy_hooks():
|
||||||
with io.open('hooks.yaml') as legacy_file:
|
with io.open('hooks.yaml', encoding='UTF-8') as legacy_file:
|
||||||
legacy = yaml.load(legacy_file.read())
|
legacy = yaml.load(legacy_file.read())
|
||||||
with io.open('.pre-commit-hooks.yaml') as hooks_file:
|
with io.open('.pre-commit-hooks.yaml', encoding='UTF-8') as hooks_file:
|
||||||
hooks = yaml.load(hooks_file.read())
|
hooks = yaml.load(hooks_file.read())
|
||||||
|
|
||||||
# The same set of hooks should be defined in both files
|
# The same set of hooks should be defined in both files
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue