build: python3 compat and fix line endings on Win (#25767)

This commit is contained in:
David Sanders 2020-10-05 17:40:04 -07:00 committed by GitHub
parent cba19f06f1
commit 53ee708fe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,8 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import print_function, unicode_literals
import argparse
import io
import os
import sys
@ -38,12 +39,11 @@ def main():
def hasTrailingWhiteSpace(filepath, fix):
try:
f = open(filepath, 'r')
lines = f.read().splitlines()
with io.open(filepath, 'r', encoding='utf-8') as f:
lines = f.read().splitlines()
except KeyboardInterrupt:
print('Keyboard interruption while parsing. Please try again.')
finally:
f.close()
return
fixed_lines = []
for num, line in enumerate(lines):
@ -53,7 +53,7 @@ def hasTrailingWhiteSpace(filepath, fix):
num + 1, filepath))
return True
if fix:
with open(filepath, 'w') as f:
with io.open(filepath, 'w', newline='\n', encoding='utf-8') as f:
print(fixed_lines)
f.writelines(fixed_lines)