Skip to content

Commit fdf82ba

Browse files
committed
Update all subprocess.check_output functions in CI scripts to be Python 3.4 compatible
Removing the 'universal_newlines' and 'encoding' args from the subprocess.check_outputs fuction. 'universal_newlines' is supported in 3.4, but 'encoding' is not. Without specifying 'encoding' it will make a guess at encoding, which can break things on BSD systems. We must handle encoding/decoding ourselves until we can use Python 3.6
1 parent fcb6694 commit fdf82ba

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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, encoding='utf8').splitlines()[0]
94+
branch = subprocess.check_output([GIT, 'show', '-s', '--format=%H', initial_commit]).decode('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, encoding='utf8').splitlines()[0].split(' ')
115+
parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', prev_commit]).decode('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, encoding='utf8').splitlines():
125+
if ("Tree-SHA512: {}".format(tree_hash)) not in subprocess.check_output([GIT, 'show', '-s', '--format=format:%B', current_commit]).decode('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, encoding='utf8').splitlines()[0].split(' ')
130+
parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', current_commit]).decode('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, encoding='utf8').splitlines()[0])
136+
commit_time = int(subprocess.check_output([GIT, 'show', '-s', '--format=format:%ct', current_commit]).decode('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, encoding='utf8').splitlines()[0]
140+
current_tree = subprocess.check_output([GIT, 'show', '--format=%T', current_commit]).decode('utf8').splitlines()[0]
141141
subprocess.call([GIT, 'checkout', '--force', '--quiet', parents[0]])
142142
subprocess.call([GIT, 'merge', '--no-ff', '--quiet', '--no-gpg-sign', parents[1]], stdout=subprocess.DEVNULL)
143-
recreated_tree = subprocess.check_output([GIT, 'show', '--format=format:%T', 'HEAD'], universal_newlines=True, encoding='utf8').splitlines()[0]
143+
recreated_tree = subprocess.check_output([GIT, 'show', '--format=format:%T', 'HEAD']).decode('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
@@ -30,8 +30,8 @@ def main():
3030
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True, encoding='utf8')
3131
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True, encoding='utf8')
3232
else:
33-
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True) # encoding='utf8'
34-
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True) # encoding='utf8'
33+
used = check_output(CMD_GREP_ARGS, shell=True).decode('utf8').strip()
34+
docd = check_output(CMD_GREP_DOCS, shell=True).decode('utf8').strip()
3535

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

0 commit comments

Comments
 (0)