Skip to content

Commit 5a2c766

Browse files
committed
Auto merge of #25749 - richo:python3, r=alexcrichton
This is enough to make `make tidy` work if you're using python3 There's definitely more stuff to do, but PR'ing now to avoid bitrot
2 parents a97b3ff + 96d7400 commit 5a2c766

File tree

5 files changed

+42
-177
lines changed

5 files changed

+42
-177
lines changed

src/etc/2014-06-rewrite-bytes-macros.py

-138
This file was deleted.

src/etc/check-summary.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def summarise(fname):
3434
summaries.append((fname, summary))
3535

3636
def count(t):
37-
return sum(map(lambda (f, s): len(s.get(t, [])), summaries))
37+
return sum(map(lambda f: len(f[1].get(t, [])), summaries))
3838

3939
logfiles = sys.argv[1:]
4040
for files in map(glob.glob, logfiles):
@@ -43,15 +43,15 @@ def count(t):
4343
failed = count('failed')
4444
ignored = count('ignored')
4545
measured = count('bench')
46-
print "summary of %d test runs: %d passed; %d failed; %d ignored; %d measured" % \
47-
(len(logfiles), ok, failed, ignored, measured)
48-
print ""
46+
print("summary of %d test runs: %d passed; %d failed; %d ignored; %d measured" %
47+
(len(logfiles), ok, failed, ignored, measured))
48+
print("")
4949

5050
if failed > 0:
51-
print "failed tests:"
51+
print("failed tests:")
5252
for f, s in summaries:
5353
failures = s.get('failed', [])
5454
if len(failures) > 0:
55-
print " %s:" % (f)
55+
print(" %s:" % (f))
5656
for test in failures:
57-
print " %s" % (test)
57+
print(" %s" % (test))

src/etc/errorck.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import re
1717

1818
if len(sys.argv) < 2:
19-
print "usage: errorck.py <src-dir>"
19+
print("usage: errorck.py <src-dir>")
2020
sys.exit(1)
2121

2222
src_dir = sys.argv[1]

src/etc/featureck.py

+28-25
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
# since the same version
1919
# * Prints information about features
2020

21-
import sys, os, re
21+
import sys
22+
import os
23+
import re
24+
import codecs
2225

2326
if len(sys.argv) < 2:
24-
print "usage: featurkck.py <src-dir>"
27+
print("usage: featureck.py <src-dir>")
2528
sys.exit(1)
2629

2730
src_dir = sys.argv[1]
@@ -47,7 +50,7 @@
4750
line = line.replace("(", "").replace("),", "").replace(")", "")
4851
parts = line.split(",")
4952
if len(parts) != 3:
50-
print "error: unexpected number of components in line: " + original_line
53+
print("error: unexpected number of components in line: " + original_line)
5154
sys.exit(1)
5255
feature_name = parts[0].strip().replace('"', "")
5356
since = parts[1].strip().replace('"', "")
@@ -79,7 +82,7 @@
7982
continue
8083

8184
path = os.path.join(dirpath, filename)
82-
with open(path, 'r') as f:
85+
with codecs.open(filename=path, mode='r', encoding="utf-8") as f:
8386
line_num = 0
8487
for line in f:
8588
line_num += 1
@@ -107,9 +110,9 @@
107110
if not mm is None:
108111
since = mm.group(1)
109112
else:
110-
print "error: misformed stability attribute"
111-
print "line " + str(line_num) + " of " + path + ":"
112-
print line
113+
print("error: misformed stability attribute")
114+
print("line %d of %:" % (line_num, path))
115+
print(line)
113116
errors = True
114117

115118
lib_features[feature_name] = feature_name
@@ -123,24 +126,24 @@
123126
(expected_since, source_path, source_line_num, source_line) = \
124127
lib_features_and_level.get((feature_name, level))
125128
if since != expected_since:
126-
print "error: mismatch in " + level + " feature '" + feature_name + "'"
127-
print "line " + str(source_line_num) + " of " + source_path + ":"
128-
print source_line
129-
print "line " + str(line_num) + " of " + path + ":"
130-
print line
129+
print("error: mismatch in %s feature '%s'" % (level, feature_name))
130+
print("line %d of %s:" % (source_line_num, source_path))
131+
print(source_line)
132+
print("line %d of %s:" % (line_num, path))
133+
print(line)
131134
errors = True
132135

133136
# Verify that this lib feature doesn't duplicate a lang feature
134137
if feature_name in language_feature_names:
135-
print "error: lib feature '" + feature_name + "' duplicates a lang feature"
136-
print "line " + str(line_num) + " of " + path + ":"
137-
print line
138+
print("error: lib feature '%s' duplicates a lang feature" % (feature_name))
139+
print("line %d of %s:" % (line_num, path))
140+
print(line)
138141
errors = True
139142

140143
else:
141-
print "error: misformed stability attribute"
142-
print "line " + str(line_num) + " of " + path + ":"
143-
print line
144+
print("error: misformed stability attribute")
145+
print("line %d of %s:" % (line_num, path))
146+
print(line)
144147
errors = True
145148

146149
# Merge data about both lists
@@ -175,7 +178,7 @@
175178
is_unstable = lib_features_and_level.get((name, "unstable")) is not None
176179

177180
if is_stable and is_unstable:
178-
print "error: feature '" + name + "' is both stable and unstable"
181+
print("error: feature '%s' is both stable and unstable" % (name))
179182
errors = True
180183

181184
if is_stable:
@@ -192,21 +195,21 @@
192195
for name in lib_feature_stats:
193196
if language_feature_stats.get(name) is not None:
194197
if not name in joint_features:
195-
print "error: feature '" + name + "' is both a lang and lib feature but not whitelisted"
198+
print("error: feature '%s' is both a lang and lib feature but not whitelisted" % (name))
196199
errors = True
197200
lang_status = language_feature_stats[name][3]
198201
lib_status = lib_feature_stats[name][3]
199202
lang_stable_since = language_feature_stats[name][4]
200203
lib_stable_since = lib_feature_stats[name][4]
201204

202205
if lang_status != lib_status and lib_status != "deprecated":
203-
print "error: feature '" + name + "' has lang status " + lang_status + \
204-
" but lib status " + lib_status
206+
print("error: feature '%s' has lang status %s " +
207+
"but lib status %s" % (name, lang_status, lib_status))
205208
errors = True
206209

207210
if lang_stable_since != lib_stable_since:
208-
print "error: feature '" + name + "' has lang stable since " + lang_stable_since + \
209-
" but lib stable since " + lib_stable_since
211+
print("error: feature '%s' has lang stable since %s " +
212+
"but lib stable since %s" % (name, lang_stable_since, lib_stable_since))
210213
errors = True
211214

212215
merged_stats[name] = (name, True, True, lang_status, lang_stable_since)
@@ -240,5 +243,5 @@
240243

241244
print
242245
for line in lines:
243-
print "* " + line
246+
print("* " + line)
244247
print

src/etc/tidy.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def interesting_file(f):
8181
check_linelength = True
8282

8383
if len(sys.argv) < 2:
84-
print "usage: tidy.py <src-dir>"
84+
print("usage: tidy.py <src-dir>")
8585
sys.exit(1)
8686

8787
src_dir = sys.argv[1]
@@ -200,10 +200,10 @@ def interesting_file(f):
200200

201201
print
202202
for ext in sorted(file_counts, key=file_counts.get, reverse=True):
203-
print "* linted {} {} files".format(file_counts[ext], ext)
204-
print "* linted {} other files".format(count_other_linted_files)
205-
print "* total lines of code: {}".format(count_lines)
206-
print "* total non-blank lines of code: {}".format(count_non_blank_lines)
207-
print
203+
print("* linted {} {} files".format(file_counts[ext], ext))
204+
print("* linted {} other files".format(count_other_linted_files))
205+
print("* total lines of code: {}".format(count_lines))
206+
print("* total non-blank lines of code: {}".format(count_non_blank_lines))
207+
print()
208208

209209
sys.exit(err)

0 commit comments

Comments
 (0)