Skip to content

Commit e571e0c

Browse files
committed
Reformat Python code
1 parent d5eb93b commit e571e0c

30 files changed

+1738
-1041
lines changed

compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def check_duplicates():
3838
if line == "};":
3939
# We're done!
4040
if found == 0:
41-
print("No intrinsics found in manual code even though we found the "
42-
"marker... Aborting...")
41+
print(
42+
"No intrinsics found in manual code even though we found the "
43+
"marker... Aborting..."
44+
)
4345
return 1
4446
for error in errors:
4547
print("ERROR => {}".format(error))
@@ -50,12 +52,17 @@ def check_duplicates():
5052
found += 1
5153
if parts[1] in intrinsics_map:
5254
if parts[3] != intrinsics_map[parts[1]]:
53-
print("Same intrinsics (`{}` at line {}) but different GCC "
55+
print(
56+
"Same intrinsics (`{}` at line {}) but different GCC "
5457
"translations: `{}` != `{}`".format(
55-
parts[1], pos, intrinsics_map[parts[1]], parts[3]))
58+
parts[1], pos, intrinsics_map[parts[1]], parts[3]
59+
)
60+
)
5661
else:
57-
errors.append("Duplicated intrinsics: `{}` at line {}. Please remove it "
58-
" from manual code".format(parts[1], pos))
62+
errors.append(
63+
"Duplicated intrinsics: `{}` at line {}. Please remove it "
64+
" from manual code".format(parts[1], pos)
65+
)
5966
# Weird but whatever...
6067
return 1 if len(errors) != 0 else 0
6168
pos += 1

compiler/rustc_codegen_gcc/tools/generate_intrinsics.py

+27-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ def run_command(command, cwd=None):
1515
def clone_repository(repo_name, path, repo_url, sub_paths=None):
1616
if os.path.exists(path):
1717
while True:
18-
choice = input("There is already a `{}` folder, do you want to update it? [y/N]".format(path))
18+
choice = input(
19+
"There is already a `{}` folder, do you want to update it? [y/N]".format(
20+
path
21+
)
22+
)
1923
if choice == "" or choice.lower() == "n":
2024
print("Skipping repository update.")
2125
return
@@ -29,7 +33,9 @@ def clone_repository(repo_name, path, repo_url, sub_paths=None):
2933
if sub_paths is None:
3034
run_command(["git", "clone", repo_url, "--depth", "1", path])
3135
else:
32-
run_command(["git", "clone", repo_url, "--filter=tree:0", "--no-checkout", path])
36+
run_command(
37+
["git", "clone", repo_url, "--filter=tree:0", "--no-checkout", path]
38+
)
3339
run_command(["git", "sparse-checkout", "init"], cwd=path)
3440
run_command(["git", "sparse-checkout", "set", *sub_paths], cwd=path)
3541
run_command(["git", "checkout"], cwd=path)
@@ -40,8 +46,8 @@ def append_intrinsic(array, intrinsic_name, translation):
4046

4147

4248
def convert_to_string(content):
43-
if content.__class__.__name__ == 'bytes':
44-
return content.decode('utf-8')
49+
if content.__class__.__name__ == "bytes":
50+
return content.decode("utf-8")
4551
return content
4652

4753

@@ -82,7 +88,7 @@ def extract_intrinsics_from_llvm(llvm_path, intrinsics):
8288

8389
def append_translation(json_data, p, array):
8490
it = json_data["index"][p]
85-
content = it["docs"].split('`')
91+
content = it["docs"].split("`")
8692
if len(content) != 5:
8793
return
8894
append_intrinsic(array, content[1], content[3])
@@ -170,22 +176,32 @@ def update_intrinsics(llvm_path, llvmint, llvmint2):
170176
)
171177
print("Updating content of `{}`...".format(output_file))
172178
with open(output_file, "w", encoding="utf8") as out:
173-
out.write("// File generated by `rustc_codegen_gcc/tools/generate_intrinsics.py`\n")
179+
out.write(
180+
"// File generated by `rustc_codegen_gcc/tools/generate_intrinsics.py`\n"
181+
)
174182
out.write("// DO NOT EDIT IT!\n")
175183
out.write("match name {\n")
176184
for arch in archs:
177185
if len(intrinsics[arch]) == 0:
178186
continue
179187
intrinsics[arch].sort(key=lambda x: (x[0], x[2]))
180-
out.write(' // {}\n'.format(arch))
188+
out.write(" // {}\n".format(arch))
181189
for entry in intrinsics[arch]:
182-
if entry[2] is True: # if it is a duplicate
183-
out.write(' // [DUPLICATE]: "{}" => "{}",\n'.format(entry[0], entry[1]))
190+
if entry[2] is True: # if it is a duplicate
191+
out.write(
192+
' // [DUPLICATE]: "{}" => "{}",\n'.format(entry[0], entry[1])
193+
)
184194
elif "_round_mask" in entry[1]:
185-
out.write(' // [INVALID CONVERSION]: "{}" => "{}",\n'.format(entry[0], entry[1]))
195+
out.write(
196+
' // [INVALID CONVERSION]: "{}" => "{}",\n'.format(
197+
entry[0], entry[1]
198+
)
199+
)
186200
else:
187201
out.write(' "{}" => "{}",\n'.format(entry[0], entry[1]))
188-
out.write(' _ => unimplemented!("***** unsupported LLVM intrinsic {}", name),\n')
202+
out.write(
203+
' _ => unimplemented!("***** unsupported LLVM intrinsic {}", name),\n'
204+
)
189205
out.write("}\n")
190206
print("Done!")
191207

library/core/src/unicode/printable.py

+34-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import os
1010
import subprocess
1111

12-
NUM_CODEPOINTS=0x110000
12+
NUM_CODEPOINTS = 0x110000
13+
1314

1415
def to_ranges(iter):
1516
current = None
@@ -23,19 +24,25 @@ def to_ranges(iter):
2324
if current is not None:
2425
yield tuple(current)
2526

27+
2628
def get_escaped(codepoints):
2729
for c in codepoints:
28-
if (c.class_ or "Cn") in "Cc Cf Cs Co Cn Zl Zp Zs".split() and c.value != ord(' '):
30+
if (c.class_ or "Cn") in "Cc Cf Cs Co Cn Zl Zp Zs".split() and c.value != ord(
31+
" "
32+
):
2933
yield c.value
3034

35+
3136
def get_file(f):
3237
try:
3338
return open(os.path.basename(f))
3439
except FileNotFoundError:
3540
subprocess.run(["curl", "-O", f], check=True)
3641
return open(os.path.basename(f))
3742

38-
Codepoint = namedtuple('Codepoint', 'value class_')
43+
44+
Codepoint = namedtuple("Codepoint", "value class_")
45+
3946

4047
def get_codepoints(f):
4148
r = csv.reader(f, delimiter=";")
@@ -66,13 +73,14 @@ def get_codepoints(f):
6673
for c in range(prev_codepoint + 1, NUM_CODEPOINTS):
6774
yield Codepoint(c, None)
6875

76+
6977
def compress_singletons(singletons):
70-
uppers = [] # (upper, # items in lowers)
78+
uppers = [] # (upper, # items in lowers)
7179
lowers = []
7280

7381
for i in singletons:
7482
upper = i >> 8
75-
lower = i & 0xff
83+
lower = i & 0xFF
7684
if len(uppers) == 0 or uppers[-1][0] != upper:
7785
uppers.append((upper, 1))
7886
else:
@@ -82,10 +90,11 @@ def compress_singletons(singletons):
8290

8391
return uppers, lowers
8492

93+
8594
def compress_normal(normal):
8695
# lengths 0x00..0x7f are encoded as 00, 01, ..., 7e, 7f
8796
# lengths 0x80..0x7fff are encoded as 80 80, 80 81, ..., ff fe, ff ff
88-
compressed = [] # [truelen, (truelenaux), falselen, (falselenaux)]
97+
compressed = [] # [truelen, (truelenaux), falselen, (falselenaux)]
8998

9099
prev_start = 0
91100
for start, count in normal:
@@ -95,21 +104,22 @@ def compress_normal(normal):
95104

96105
assert truelen < 0x8000 and falselen < 0x8000
97106
entry = []
98-
if truelen > 0x7f:
107+
if truelen > 0x7F:
99108
entry.append(0x80 | (truelen >> 8))
100-
entry.append(truelen & 0xff)
109+
entry.append(truelen & 0xFF)
101110
else:
102-
entry.append(truelen & 0x7f)
103-
if falselen > 0x7f:
111+
entry.append(truelen & 0x7F)
112+
if falselen > 0x7F:
104113
entry.append(0x80 | (falselen >> 8))
105-
entry.append(falselen & 0xff)
114+
entry.append(falselen & 0xFF)
106115
else:
107-
entry.append(falselen & 0x7f)
116+
entry.append(falselen & 0x7F)
108117

109118
compressed.append(entry)
110119

111120
return compressed
112121

122+
113123
def print_singletons(uppers, lowers, uppersname, lowersname):
114124
print("#[rustfmt::skip]")
115125
print("const {}: &[(u8, u8)] = &[".format(uppersname))
@@ -119,22 +129,26 @@ def print_singletons(uppers, lowers, uppersname, lowersname):
119129
print("#[rustfmt::skip]")
120130
print("const {}: &[u8] = &[".format(lowersname))
121131
for i in range(0, len(lowers), 8):
122-
print(" {}".format(" ".join("{:#04x},".format(x) for x in lowers[i:i+8])))
132+
print(
133+
" {}".format(" ".join("{:#04x},".format(x) for x in lowers[i : i + 8]))
134+
)
123135
print("];")
124136

137+
125138
def print_normal(normal, normalname):
126139
print("#[rustfmt::skip]")
127140
print("const {}: &[u8] = &[".format(normalname))
128141
for v in normal:
129142
print(" {}".format(" ".join("{:#04x},".format(i) for i in v)))
130143
print("];")
131144

145+
132146
def main():
133147
file = get_file("https://www.unicode.org/Public/UNIDATA/UnicodeData.txt")
134148

135149
codepoints = get_codepoints(file)
136150

137-
CUTOFF=0x10000
151+
CUTOFF = 0x10000
138152
singletons0 = []
139153
singletons1 = []
140154
normal0 = []
@@ -234,10 +248,11 @@ def main():
234248
}\
235249
""")
236250
print()
237-
print_singletons(singletons0u, singletons0l, 'SINGLETONS0U', 'SINGLETONS0L')
238-
print_singletons(singletons1u, singletons1l, 'SINGLETONS1U', 'SINGLETONS1L')
239-
print_normal(normal0, 'NORMAL0')
240-
print_normal(normal1, 'NORMAL1')
251+
print_singletons(singletons0u, singletons0l, "SINGLETONS0U", "SINGLETONS0L")
252+
print_singletons(singletons1u, singletons1l, "SINGLETONS1U", "SINGLETONS1L")
253+
print_normal(normal0, "NORMAL0")
254+
print_normal(normal1, "NORMAL1")
255+
241256

242-
if __name__ == '__main__':
257+
if __name__ == "__main__":
243258
main()

0 commit comments

Comments
 (0)