Skip to content

Commit 3c6b3ab

Browse files
[benchmark] Fix linter errors in create_benchmark.py
1 parent 0b3fa54 commit 3c6b3ab

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

benchmark/scripts/create_benchmark.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66

7+
78
def main():
89
p = argparse.ArgumentParser()
910
p.add_argument('name', help='The name of the new benchmark to be created')
@@ -18,6 +19,7 @@ def main():
1819
# registers the benchmark with the driver in `main.swift`
1920
add_register_benchmark(args.name)
2021

22+
2123
def update_cmakelists(name):
2224
"""Adds a new entry to the `CMakeLists.txt` file with the given
2325
benchmark name.
@@ -38,11 +40,12 @@ def update_cmakelists(name):
3840
for line in file_new_contents:
3941
f.write(line)
4042

43+
4144
def create_benchmark_file(name):
4245
"""Creates a new Swift file with the given name based on the template
4346
and places it in the `single-source` directory.
4447
"""
45-
48+
4649
template_path = create_relative_path('Template.swift')
4750
benchmark_template = ''
4851
with open(template_path, 'r') as f:
@@ -56,6 +59,7 @@ def create_benchmark_file(name):
5659
with open(source_file_path, 'w') as f:
5760
f.write(formatted_template)
5861

62+
5963
def add_import_benchmark(name):
6064
"""Adds an `import` statement to the `main.swift` file for the new
6165
benchmark.
@@ -80,8 +84,8 @@ def add_import_benchmark(name):
8084
benchmark_name = match.group(1)
8185
# find where to insert the new benchmark in the right alphabetical
8286
# order.
83-
if ((name < benchmark_name and previous_benchmark_name is None) or
84-
(name < benchmark_name and name > previous_benchmark_name)):
87+
if (name < benchmark_name and previous_benchmark_name is None or
88+
name < benchmark_name and name > previous_benchmark_name):
8589
if read_test_dependencies:
8690
file_new_contents.append('import ' + name + '\n' + line)
8791
else:
@@ -98,6 +102,7 @@ def add_import_benchmark(name):
98102
for line in file_new_contents:
99103
f.write(line)
100104

105+
101106
def add_register_benchmark(name):
102107
"""Adds an `import` statement to the `main.swift` file for the new
103108
benchmark.
@@ -118,9 +123,10 @@ def add_register_benchmark(name):
118123
for line in file_new_contents:
119124
f.write(line)
120125

126+
121127
def insert_line_alphabetically(name, new_line, lines, regex):
122-
"""Iterates through the given lines and executes the regex on each line
123-
to find where the new benchmark should be inserted with the given `new_line`.
128+
"""Iterates through the given lines and executes the regex on each line to
129+
find where the new benchmark should be inserted with the given `new_line`.
124130
"""
125131
# the name of the previous seen benchmark in order to insert the new
126132
# one at the correct position
@@ -134,8 +140,8 @@ def insert_line_alphabetically(name, new_line, lines, regex):
134140
benchmark_name = match.group(1)
135141
# check if we're at the line where we have to insert the new
136142
# benchmark in the correct alphabetical order
137-
if ((name < benchmark_name and previous_benchmark_name is None) or
138-
(name < benchmark_name and name > previous_benchmark_name)):
143+
if (name < benchmark_name and previous_benchmark_name is None or
144+
name < benchmark_name and name > previous_benchmark_name):
139145
updated_lines.append(new_line + line)
140146
else:
141147
updated_lines.append(line)
@@ -144,8 +150,10 @@ def insert_line_alphabetically(name, new_line, lines, regex):
144150
updated_lines.append(line)
145151
return updated_lines
146152

153+
147154
def create_relative_path(file_path):
148155
return os.path.join(os.path.dirname(__file__), file_path)
149156

157+
150158
if __name__ == "__main__":
151159
main()

0 commit comments

Comments
 (0)