diff --git a/.gitignore b/.gitignore index fc72fdb4..c00e966c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ /venv* coverage-html dist +# SublimeText project/workspace files +*.sublime-* diff --git a/pre_commit_hooks/autopep8_wrapper.py b/pre_commit_hooks/autopep8_wrapper.py index 52aaebe3..b2d2d0c1 100644 --- a/pre_commit_hooks/autopep8_wrapper.py +++ b/pre_commit_hooks/autopep8_wrapper.py @@ -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 diff --git a/pre_commit_hooks/check_docstring_first.py b/pre_commit_hooks/check_docstring_first.py index f2f5b729..08968127 100644 --- a/pre_commit_hooks/check_docstring_first.py +++ b/pre_commit_hooks/check_docstring_first.py @@ -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 diff --git a/pre_commit_hooks/string_fixer.py b/pre_commit_hooks/string_fixer.py index 3523e8a0..f73f09da 100644 --- a/pre_commit_hooks/string_fixer.py +++ b/pre_commit_hooks/string_fixer.py @@ -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 @@ -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: diff --git a/testing/util.py b/testing/util.py index 837a3cb2..c5e45472 100644 --- a/testing/util.py +++ b/testing/util.py @@ -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) diff --git a/tests/meta_test.py b/tests/meta_test.py index 29e06a8c..e5d068fd 100644 --- a/tests/meta_test.py +++ b/tests/meta_test.py @@ -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