Skip to content

Commit fa61627

Browse files
committed
Merge #14128: lint: Make sure we read the command line inputs using utf-8 decoding in python
5d62dcf lint: Make sure we read the command line inputs using utf-8 decoding in python (Chun Kuan Lee) Pull request description: Make sure we read the command line inputs using utf-8 decoding in python occurred from travis cron job: contrib/verify-commits/verify-commits.py should run with utf-8, otherwise it would raise UnicodeDecodeError `UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 744: ordinal not in range(128)` Tree-SHA512: 90e4ad57fdbbbecb0a21fc2d2b03a04f5ef125e54124719ef36e5a85326930b732b47534757a7c3a8730096f3947b009ec898191928b5c2d38f9f4b3e37db48d
2 parents 281feee + 5d62dcf commit fa61627

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

contrib/devtools/optimize-pngs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def content_hash(filename):
2727
pngcrush = 'pngcrush'
2828
git = 'git'
2929
folders = ["src/qt/res/movies", "src/qt/res/icons", "share/pixmaps"]
30-
basePath = subprocess.check_output([git, 'rev-parse', '--show-toplevel'], universal_newlines=True).rstrip('\n')
30+
basePath = subprocess.check_output([git, 'rev-parse', '--show-toplevel'], universal_newlines=True, encoding='utf8').rstrip('\n')
3131
totalSaveBytes = 0
3232
noHashChange = True
3333

@@ -50,7 +50,7 @@ def content_hash(filename):
5050
sys.exit(0)
5151

5252
#verify
53-
if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT, universal_newlines=True):
53+
if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf8'):
5454
print("PNG file "+file+" is corrupted after crushing, check out pngcursh version")
5555
sys.exit(1)
5656

contrib/gitian-build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def main():
209209
subprocess.check_call(['git', 'fetch', args.url, 'refs/pull/'+args.version+'/merge'])
210210
os.chdir('../gitian-builder/inputs/bitcoin')
211211
subprocess.check_call(['git', 'fetch', args.url, 'refs/pull/'+args.version+'/merge'])
212-
args.commit = subprocess.check_output(['git', 'show', '-s', '--format=%H', 'FETCH_HEAD'], universal_newlines=True).strip()
212+
args.commit = subprocess.check_output(['git', 'show', '-s', '--format=%H', 'FETCH_HEAD'], universal_newlines=True, encoding='utf8').strip()
213213
args.version = 'pull-' + args.version
214214
print(args.commit)
215215
subprocess.check_call(['git', 'fetch'])

contrib/verify-commits/verify-commits.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def main():
9191
no_sha1 = True
9292
prev_commit = ""
9393
initial_commit = current_commit
94-
branch = subprocess.check_output([GIT, 'show', '-s', '--format=%H', initial_commit], universal_newlines=True).splitlines()[0]
94+
branch = subprocess.check_output([GIT, 'show', '-s', '--format=%H', initial_commit], universal_newlines=True, encoding='utf8').splitlines()[0]
9595

9696
# Iterate through commits
9797
while True:
@@ -112,7 +112,7 @@ def main():
112112
if prev_commit != "":
113113
print("No parent of {} was signed with a trusted key!".format(prev_commit), file=sys.stderr)
114114
print("Parents are:", file=sys.stderr)
115-
parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', prev_commit], universal_newlines=True).splitlines()[0].split(' ')
115+
parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', prev_commit], universal_newlines=True, encoding='utf8').splitlines()[0].split(' ')
116116
for parent in parents:
117117
subprocess.call([GIT, 'show', '-s', parent], stdout=sys.stderr)
118118
else:
@@ -122,25 +122,25 @@ def main():
122122
# Check the Tree-SHA512
123123
if (verify_tree or prev_commit == "") and current_commit not in incorrect_sha512_allowed:
124124
tree_hash = tree_sha512sum(current_commit)
125-
if ("Tree-SHA512: {}".format(tree_hash)) not in subprocess.check_output([GIT, 'show', '-s', '--format=format:%B', current_commit], universal_newlines=True).splitlines():
125+
if ("Tree-SHA512: {}".format(tree_hash)) not in subprocess.check_output([GIT, 'show', '-s', '--format=format:%B', current_commit], universal_newlines=True, encoding='utf8').splitlines():
126126
print("Tree-SHA512 did not match for commit " + current_commit, file=sys.stderr)
127127
sys.exit(1)
128128

129129
# Merge commits should only have two parents
130-
parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', current_commit], universal_newlines=True).splitlines()[0].split(' ')
130+
parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', current_commit], universal_newlines=True, encoding='utf8').splitlines()[0].split(' ')
131131
if len(parents) > 2:
132132
print("Commit {} is an octopus merge".format(current_commit), file=sys.stderr)
133133
sys.exit(1)
134134

135135
# Check that the merge commit is clean
136-
commit_time = int(subprocess.check_output([GIT, 'show', '-s', '--format=format:%ct', current_commit], universal_newlines=True).splitlines()[0])
136+
commit_time = int(subprocess.check_output([GIT, 'show', '-s', '--format=format:%ct', current_commit], universal_newlines=True, encoding='utf8').splitlines()[0])
137137
check_merge = commit_time > time.time() - args.clean_merge * 24 * 60 * 60 # Only check commits in clean_merge days
138138
allow_unclean = current_commit in unclean_merge_allowed
139139
if len(parents) == 2 and check_merge and not allow_unclean:
140-
current_tree = subprocess.check_output([GIT, 'show', '--format=%T', current_commit], universal_newlines=True).splitlines()[0]
140+
current_tree = subprocess.check_output([GIT, 'show', '--format=%T', current_commit], universal_newlines=True, encoding='utf8').splitlines()[0]
141141
subprocess.call([GIT, 'checkout', '--force', '--quiet', parents[0]])
142142
subprocess.call([GIT, 'merge', '--no-ff', '--quiet', parents[1]], stdout=subprocess.DEVNULL)
143-
recreated_tree = subprocess.check_output([GIT, 'show', '--format=format:%T', 'HEAD'], universal_newlines=True).splitlines()[0]
143+
recreated_tree = subprocess.check_output([GIT, 'show', '--format=format:%T', 'HEAD'], universal_newlines=True, encoding='utf8').splitlines()[0]
144144
if current_tree != recreated_tree:
145145
print("Merge commit {} is not clean".format(current_commit), file=sys.stderr)
146146
subprocess.call([GIT, 'diff', current_commit])

test/lint/check-doc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727

2828
def main():
29-
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True)
30-
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True)
29+
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True, encoding='utf8')
30+
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True, encoding='utf8')
3131

3232
args_used = set(re.findall(re.compile(REGEX_ARG), used))
3333
args_docd = set(re.findall(re.compile(REGEX_DOC), docd)).union(SET_DOC_OPTIONAL)

test/lint/lint-python-utf8-encoding.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ if [[ ${OUTPUT} != "" ]]; then
1717
echo "${OUTPUT}"
1818
EXIT_CODE=1
1919
fi
20+
OUTPUT=$(git grep "check_output(" -- "*.py" | grep "universal_newlines=True" | grep -vE "encoding=.(ascii|utf8|utf-8).")
21+
if [[ ${OUTPUT} != "" ]]; then
22+
echo "Python's check_output(...) seems to be used to get program outputs without explicitly"
23+
echo "specifying encoding=\"utf8\":"
24+
echo
25+
echo "${OUTPUT}"
26+
EXIT_CODE=1
27+
fi
2028
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)