Skip to content

Commit 588232e

Browse files
authored
Merge pull request #279 from nvtkaszpir/fix/non-utf8-opens
Open files as UTF-8
2 parents 16ff195 + 54c0f8c commit 588232e

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
/venv*
1313
coverage-html
1414
dist
15+
# SublimeText project/workspace files
16+
*.sublime-*

pre_commit_hooks/autopep8_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def main(argv=None):
1414

1515
retv = 0
1616
for filename in args.files:
17-
original_contents = io.open(filename).read()
17+
original_contents = io.open(filename, encoding='UTF-8').read()
1818
new_contents = autopep8.fix_code(original_contents, args)
1919
if original_contents != new_contents:
2020
print('Fixing {}'.format(filename))
2121
retv = 1
22-
with io.open(filename, 'w') as output_file:
22+
with io.open(filename, 'w', encoding='UTF-8') as output_file:
2323
output_file.write(new_contents)
2424

2525
return retv

pre_commit_hooks/check_docstring_first.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def main(argv=None):
5858
retv = 0
5959

6060
for filename in args.filenames:
61-
contents = io.open(filename).read()
61+
contents = io.open(filename, encoding='UTF-8').read()
6262
retv |= check_docstring_first(contents, filename=filename)
6363

6464
return retv

pre_commit_hooks/string_fixer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_line_offsets_by_line_no(src):
3232

3333

3434
def fix_strings(filename):
35-
contents = io.open(filename).read()
35+
contents = io.open(filename, encoding='UTF-8').read()
3636
line_offsets = get_line_offsets_by_line_no(contents)
3737

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

5353
new_contents = ''.join(splitcontents)
5454
if contents != new_contents:
55-
with io.open(filename, 'w') as write_handle:
55+
with io.open(filename, 'w', encoding='UTF-8') as write_handle:
5656
write_handle.write(new_contents)
5757
return 1
5858
else:

testing/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def get_resource_path(path):
1414

1515
def write_file(filename, contents):
1616
"""Hax because coveragepy chokes on nested context managers."""
17-
with io.open(filename, 'w', newline='') as file_obj:
17+
with io.open(filename, 'w', encoding='UTF-8', newline='') as file_obj:
1818
file_obj.write(contents)

tests/meta_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def _assert_parseable_in_old_pre_commit(hooks):
1212

1313

1414
def test_legacy_hooks():
15-
with io.open('hooks.yaml') as legacy_file:
15+
with io.open('hooks.yaml', encoding='UTF-8') as legacy_file:
1616
legacy = yaml.load(legacy_file.read())
17-
with io.open('.pre-commit-hooks.yaml') as hooks_file:
17+
with io.open('.pre-commit-hooks.yaml', encoding='UTF-8') as hooks_file:
1818
hooks = yaml.load(hooks_file.read())
1919

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

0 commit comments

Comments
 (0)