Fix encoding problem with json validation in PRESUBMIT.py.
The presubmit script was calling out to a subprocess to discard
comments in json files.
https://codereview.chromium.org/1253453002
exposed some encoding issue when sending the Unicode content back
and forth. Rather than trying to figure out how to get that right, just
import and use the json_comment_eater python module directly.
BUG=513181
TESTED=git cl presubmit passed for the above-mentioned CL .
Review URL: https://codereview.chromium.org/1248323002
Cr-Commit-Position: refs/heads/master@{#340071}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index c926dd7..a888b11 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1198,15 +1198,16 @@
try:
contents = input_api.ReadFile(filename)
if eat_comments:
- json_comment_eater = input_api.os_path.join(
- input_api.PresubmitLocalPath(),
- 'tools', 'json_comment_eater', 'json_comment_eater.py')
- process = input_api.subprocess.Popen(
- [input_api.python_executable, json_comment_eater],
- stdin=input_api.subprocess.PIPE,
- stdout=input_api.subprocess.PIPE,
- universal_newlines=True)
- (contents, _) = process.communicate(input=contents)
+ import sys
+ original_sys_path = sys.path
+ try:
+ sys.path = sys.path + [input_api.os_path.join(
+ input_api.PresubmitLocalPath(),
+ 'tools', 'json_comment_eater')]
+ import json_comment_eater
+ finally:
+ sys.path = original_sys_path
+ contents = json_comment_eater.Nom(contents)
input_api.json.loads(contents)
except ValueError as e: