Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open files as UTF-8 #279

Merged
merged 1 commit into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
/venv*
coverage-html
dist
# SublimeText project/workspace files
*.sublime-*
4 changes: 2 additions & 2 deletions pre_commit_hooks/autopep8_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def main(argv=None):

retv = 0
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)
if original_contents != new_contents:
print('Fixing {}'.format(filename))
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)

return retv
Expand Down
2 changes: 1 addition & 1 deletion pre_commit_hooks/check_docstring_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main(argv=None):
retv = 0

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)

return retv
4 changes: 2 additions & 2 deletions pre_commit_hooks/string_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_line_offsets_by_line_no(src):


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)

# Basically a mutable string
Expand All @@ -52,7 +52,7 @@ def fix_strings(filename):

new_contents = ''.join(splitcontents)
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)
return 1
else:
Expand Down
2 changes: 1 addition & 1 deletion testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def get_resource_path(path):

def write_file(filename, contents):
"""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)
4 changes: 2 additions & 2 deletions tests/meta_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def _assert_parseable_in_old_pre_commit(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())
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())

# The same set of hooks should be defined in both files
Expand Down