Skip to content

Commit a1e1813

Browse files
committed
YAML and Python lint changes
1 parent 8348862 commit a1e1813

File tree

6 files changed

+81
-55
lines changed

6 files changed

+81
-55
lines changed

.github/workflows/pull_request.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ jobs:
2020
with:
2121
license_header_check_project_name: "Swift.org"
2222
unacceptable_language_check_enabled: false
23-

Utils/benchmark-generators/generateDiceNotation.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,59 @@
1717
minDigits = 1
1818
maxDigits = 4
1919

20+
2021
def number():
21-
return "".join([random.choice(string.digits) for _ in range(random.randint(minDigits,maxDigits))])
22+
return "".join([random.choice(string.digits)
23+
for _ in range(random.randint(minDigits, maxDigits))])
24+
2225

2326
minWord = 5
2427
maxWord = 10
28+
29+
2530
def word():
26-
return "".join([random.choice(string.ascii_letters) for _ in range(random.randint(minWord,maxWord))])
31+
return "".join([random.choice(string.ascii_letters)
32+
for _ in range(random.randint(minWord, maxWord))])
33+
2734

2835
minDice = 1
2936
maxDice = 4
37+
38+
3039
def roll():
31-
die = []
32-
for _ in range(random.randint(minDice, maxDice)):
33-
roll = ""
34-
if random.randint(0,1) == 1:
35-
roll += number()
36-
37-
if random.randint(0,1) == 1:
38-
roll += "d" + number()
39-
else:
40-
roll += "D" + number()
41-
42-
die.append(roll)
43-
return "+".join(die)
40+
die = []
41+
for _ in range(random.randint(minDice, maxDice)):
42+
roll = ""
43+
if random.randint(0, 1) == 1:
44+
roll += number()
45+
46+
if random.randint(0, 1) == 1:
47+
roll += "d" + number()
48+
else:
49+
roll += "D" + number()
50+
51+
die.append(roll)
52+
return "+".join(die)
4453

4554

4655
line_num = 2000
4756
things_per_line = 10
4857

4958
lines = []
5059
for _ in range(line_num):
51-
line = []
52-
for _ in range(things_per_line):
53-
if random.randint(0,1) == 1:
54-
line.append(word())
55-
else:
56-
line.append(roll())
57-
lines.append(" ".join(line))
60+
line = []
61+
for _ in range(things_per_line):
62+
if random.randint(0, 1) == 1:
63+
line.append(word())
64+
else:
65+
line.append(roll())
66+
lines.append(" ".join(line))
5867

5968
dice_text = "\n ".join(lines)
6069

6170
dice_rolls = []
6271
for _ in range(2000):
63-
dice_rolls.append(roll())
72+
dice_rolls.append(roll())
6473

6574
dice_rolls_formatted = "[" + ",\n ".join(["\"" + x + "\"" for x in dice_rolls]) + "]"
6675

Utils/benchmark-generators/generateEmails.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
# issues but otherwise this should work
2727
emails = []
2828
for _ in range(n):
29-
domain_len = random.randint(2,64)
30-
locale_len = random.randint(2,64)
31-
tld_len = random.randint(2,10)
32-
33-
domain = "".join(random.sample(domain_charset, domain_len))
34-
locale = "".join(random.sample(locale_charset, locale_len))
35-
tld = "".join(random.sample(string.ascii_lowercase, tld_len))
36-
email = locale + "@" + domain + "." + tld
37-
emails.append(email)
29+
domain_len = random.randint(2, 64)
30+
locale_len = random.randint(2, 64)
31+
tld_len = random.randint(2, 10)
32+
33+
domain = "".join(random.sample(domain_charset, domain_len))
34+
locale = "".join(random.sample(locale_charset, locale_len))
35+
tld = "".join(random.sample(string.ascii_lowercase, tld_len))
36+
email = locale + "@" + domain + "." + tld
37+
emails.append(email)
3838

3939
res = """
4040
extension Inputs {{

Utils/benchmark-generators/generateNetworkingData.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,25 @@
1414

1515
random.seed(0)
1616

17+
1718
def ipv6():
18-
return ":".join(["".join([random.choice(string.hexdigits) for _ in range(4)]) for _ in range(8)])
19+
return ":".join(["".join([random.choice(string.hexdigits)
20+
for _ in range(4)]) for _ in range(8)])
21+
1922

2023
def ipv4():
21-
return ".".join([str(random.randint(1,255)) for _ in range(4)])
24+
return ".".join([str(random.randint(1, 255)) for _ in range(4)])
25+
2226

2327
def mac():
24-
x = random.randint(0,1)
25-
if x == 0:
26-
raw = "{:02x}".format(random.randint(0,2**48-1))
27-
return ":".join([raw[i:i + 2] for i in range(0, len(raw), 2)])
28-
else:
29-
raw = "{:02x}".format(random.randint(0,2**48-1))
30-
return "-".join([raw[i:i + 2] for i in range(0, len(raw), 2)])
28+
x = random.randint(0, 1)
29+
if x == 0:
30+
raw = "{:02x}".format(random.randint(0, 2**48 - 1))
31+
return ":".join([raw[i:i + 2] for i in range(0, len(raw), 2)])
32+
else:
33+
raw = "{:02x}".format(random.randint(0, 2**48 - 1))
34+
return "-".join([raw[i:i + 2] for i in range(0, len(raw), 2)])
35+
3136

3237
res = """
3338
extension Inputs {{

Utils/benchmark-generators/generateTaggedUnicode.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
minLine = 10
2828
maxLine = 100
2929

30+
3031
def get_random(i):
31-
return "".join([chr(random.randint(low, high)) for _ in range(i)])
32-
33-
lines = [start + get_random(random.randint(minLine, maxLine)) + end for _ in range(numLines)]
32+
return "".join([chr(random.randint(low, high)) for _ in range(i)])
33+
34+
35+
lines = [
36+
start + get_random(random.randint(minLine, maxLine)) + end
37+
for _ in range(numLines)
38+
]
3439

3540
print("\n".join(lines))

Utils/createBenchmark.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
##===----------------------------------------------------------------------===##
1111

1212
# python3 createBenchmark.py MyRegexBenchmark
13-
# reference: https://github.com/apple/swift/blob/main/benchmark/scripts/create_benchmark.py
13+
# reference:
14+
# https://github.com/apple/swift/blob/main/benchmark/scripts/create_benchmark.py
1415

1516
import argparse
1617
import os
1718

18-
template = """//===----------------------------------------------------------------------===//
19+
template = """\
20+
//===----------------------------------------------------------------------===//
1921
//
2022
// This source file is part of the Swift.org open source project
2123
//
@@ -34,34 +36,38 @@
3436
}}
3537
"""
3638

39+
3740
def main():
3841
p = argparse.ArgumentParser()
3942
p.add_argument("name", help="The name of the new benchmark to be created")
4043
args = p.parse_args()
41-
44+
4245
# create a file in Sources/RegexBenchmark/Suite with the benchmark template
4346
create_benchmark_file(args.name)
44-
47+
4548
# add to the registration function in BenchmarkRunner
4649
register_benchmark(args.name)
4750

51+
4852
def create_benchmark_file(name):
49-
contents = template.format(name= name)
53+
contents = template.format(name=name)
5054
relative_path = create_relative_path("../Sources/RegexBenchmark/Suite/")
5155
source_file_path = os.path.join(relative_path, name + ".swift")
52-
56+
5357
print(f"Creating new benchmark file: {source_file_path}")
5458
with open(source_file_path, "w") as f:
5559
f.write(contents)
5660

61+
5762
def register_benchmark(name):
58-
relative_path = create_relative_path("../Sources/RegexBenchmark/BenchmarkRegistration.swift")
63+
relative_path = create_relative_path(
64+
"../Sources/RegexBenchmark/BenchmarkRegistration.swift")
5965

6066
# read current contents into an array
6167
file_contents = []
6268
with open(relative_path, "r") as f:
6369
file_contents = f.readlines()
64-
70+
6571
new_file_contents = []
6672
for line in file_contents:
6773
if "end of registrations" not in line:
@@ -70,14 +76,16 @@ def register_benchmark(name):
7076
# add the newest benchmark
7177
new_file_contents.append(f" self.add{name}()\n")
7278
new_file_contents.append(line)
73-
79+
7480
# write the new contents
7581
with open(relative_path, "w") as f:
7682
for line in new_file_contents:
7783
f.write(line)
78-
84+
85+
7986
def create_relative_path(file_path):
8087
return os.path.join(os.path.dirname(__file__), file_path)
8188

89+
8290
if __name__ == "__main__":
8391
main()

0 commit comments

Comments
 (0)