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