build: python3 compat and fix line endings on Win (#25767)
This commit is contained in:
parent
cba19f06f1
commit
53ee708fe8
1 changed files with 6 additions and 6 deletions
|
@ -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')
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue