Specify encoding when opening text files
When opening a text file it is important to specify encoding='utf-8'
since otherwise the behavior will depend on your system locale. This
change fixes various encoding omissions in PRESUBMIT.py files, found
when presubmits were run when uploading crrev.com/c/4290775.
Bug: 1418846
Change-Id: Ief5f6d6bb749de95bc4071055492e6c9c6b6c56d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4292516
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index a900a01..bd03f6e 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -49,12 +49,12 @@
]
files_to_skip = list(input_api.DEFAULT_FILES_TO_SKIP)
if os.path.exists('.gitignore'):
- with open('.gitignore') as fh:
+ with open('.gitignore', encoding='utf-8') as fh:
lines = [l.strip() for l in fh.readlines()]
files_to_skip.extend([fnmatch.translate(l) for l in lines if
l and not l.startswith('#')])
if os.path.exists('.git/info/exclude'):
- with open('.git/info/exclude') as fh:
+ with open('.git/info/exclude', encoding='utf-8') as fh:
lines = [l.strip() for l in fh.readlines()]
files_to_skip.extend([fnmatch.translate(l) for l in lines if
l and not l.startswith('#')])