Skip to content

Commit 4b4fd64

Browse files
authored
Merge pull request #2709 from RossBrunton/ross/black
[NFC] Format python code with black
2 parents f9d8485 + 0f282ae commit 4b4fd64

34 files changed

+3387
-1743
lines changed

cmake/match.py

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import re
2323
from enum import Enum
2424

25+
2526
## @brief print a sequence of lines
26-
def print_lines(lines, hint = None):
27+
def print_lines(lines, hint=None):
2728
counter = 1
2829
for l in lines:
2930
hint_char = " "
@@ -34,7 +35,9 @@ def print_lines(lines, hint = None):
3435

3536

3637
## @brief print the whole content of input and match files
37-
def print_content(input_lines, match_lines, ignored_lines, hint_input = None, hint_match = None):
38+
def print_content(
39+
input_lines, match_lines, ignored_lines, hint_input=None, hint_match=None
40+
):
3841
print("------ Input Lines " + "-" * 61)
3942
print_lines(input_lines, hint_input)
4043
print("------ Match Lines " + "-" * 61)
@@ -91,10 +94,10 @@ def check_status(input_lines, match_lines):
9194
## @brief pattern matching tags.
9295
## Tags are expected to be at the start of the line.
9396
class Tag(Enum):
94-
OPT = "{{OPT}}" # makes the line optional
95-
IGNORE = "{{IGNORE}}" # ignores all input until next match or end of input file
96-
NONDETERMINISTIC = "{{NONDETERMINISTIC}}" # switches on "deterministic mode"
97-
COMMENT = "#" # comment - line ignored
97+
OPT = "{{OPT}}" # makes the line optional
98+
IGNORE = "{{IGNORE}}" # ignores all input until next match or end of input file
99+
NONDETERMINISTIC = "{{NONDETERMINISTIC}}" # switches on "deterministic mode"
100+
COMMENT = "#" # comment - line ignored
98101

99102

100103
## @brief main function for the match file processing script
@@ -106,7 +109,7 @@ def main():
106109
input_file = sys.argv[1]
107110
match_file = sys.argv[2]
108111

109-
with open(input_file, 'r') as input, open(match_file, 'r') as match:
112+
with open(input_file, "r") as input, open(match_file, "r") as match:
110113
input_lines = input.readlines()
111114
# Filter out empty lines and comments (lines beginning with the comment
112115
# character, ignoring leading whitespace)
@@ -134,7 +137,9 @@ def main():
134137
remaining_matches = set(range(len(match_lines))) - matched_lines
135138
for m in remaining_matches:
136139
line = match_lines[m]
137-
if line.startswith(Tag.OPT.value) or line.startswith(Tag.NONDETERMINISTIC.value):
140+
if line.startswith(Tag.OPT.value) or line.startswith(
141+
Tag.NONDETERMINISTIC.value
142+
):
138143
continue
139144
print_match_not_found(m + 1, match_lines[m])
140145
print_content(input_lines, match_lines, ignored_lines, hint_match=m)
@@ -143,38 +148,55 @@ def main():
143148
sys.exit(0)
144149
elif status == Status.MATCH_END:
145150
print_input_not_found(input_idx + 1, input_lines[input_idx])
146-
print_content(input_lines, match_lines, ignored_lines, hint_input=input_idx)
151+
print_content(
152+
input_lines, match_lines, ignored_lines, hint_input=input_idx
153+
)
147154
sys.exit(1)
148155
else:
149-
if (status == Status.INPUT_AND_MATCH_END) or (status == Status.MATCH_END and Tag.IGNORE in tags_in_effect):
156+
if (status == Status.INPUT_AND_MATCH_END) or (
157+
status == Status.MATCH_END and Tag.IGNORE in tags_in_effect
158+
):
150159
# all lines matched or the last line in match file is an ignore tag
151160
sys.exit(0)
152161
elif status == Status.MATCH_END:
153162
print_incorrect_match(input_idx + 1, input_lines[input_idx].strip(), "")
154-
print_content(input_lines, match_lines, ignored_lines, hint_input=input_idx)
163+
print_content(
164+
input_lines, match_lines, ignored_lines, hint_input=input_idx
165+
)
155166
sys.exit(1)
156167
elif status == Status.INPUT_END:
157-
# If we get to the end of the input, but still have pending matches,
158-
# then that's a failure unless all pending matches are optional -
159-
# otherwise we're done
168+
# If we get to the end of the input, but still have pending matches,
169+
# then that's a failure unless all pending matches are optional -
170+
# otherwise we're done
160171
while match_idx < len(match_lines):
161-
if not (match_lines[match_idx].startswith(Tag.OPT.value) or
162-
match_lines[match_idx].startswith(Tag.IGNORE.value) or
163-
match_lines[match_idx].startswith(Tag.NONDETERMINISTIC.value)):
172+
if not (
173+
match_lines[match_idx].startswith(Tag.OPT.value)
174+
or match_lines[match_idx].startswith(Tag.IGNORE.value)
175+
or match_lines[match_idx].startswith(Tag.NONDETERMINISTIC.value)
176+
):
164177
print_incorrect_match(match_idx + 1, "", match_lines[match_idx])
165-
print_content(input_lines, match_lines, ignored_lines, hint_match=match_idx)
178+
print_content(
179+
input_lines,
180+
match_lines,
181+
ignored_lines,
182+
hint_match=match_idx,
183+
)
166184
sys.exit(1)
167185
match_idx += 1
168186
sys.exit(0)
169187

170-
input_line = input_lines[input_idx].strip() if input_idx < len(input_lines) else ""
188+
input_line = (
189+
input_lines[input_idx].strip() if input_idx < len(input_lines) else ""
190+
)
171191
match_line = match_lines[match_idx]
172192

173193
# check for tags
174194
if match_line.startswith(Tag.OPT.value):
175195
tags_in_effect.append(Tag.OPT)
176-
match_line = match_line[len(Tag.OPT.value):]
177-
elif match_line.startswith(Tag.NONDETERMINISTIC.value) and not deterministic_mode:
196+
match_line = match_line[len(Tag.OPT.value) :]
197+
elif (
198+
match_line.startswith(Tag.NONDETERMINISTIC.value) and not deterministic_mode
199+
):
178200
deterministic_mode = True
179201
match_idx = 0
180202
input_idx = 0
@@ -185,10 +207,10 @@ def main():
185207
sys.exit(2)
186208
tags_in_effect.append(Tag.IGNORE)
187209
match_idx += 1
188-
continue # line with ignore tag should be skipped
210+
continue # line with ignore tag should be skipped
189211

190212
# split into parts at {{ }}
191-
match_parts = re.split(r'\{{(.*?)\}}', match_line.strip())
213+
match_parts = re.split(r"\{{(.*?)\}}", match_line.strip())
192214
pattern = ""
193215
for j, part in enumerate(match_parts):
194216
if j % 2 == 0:
@@ -218,7 +240,13 @@ def main():
218240
input_idx += 1
219241
else:
220242
print_incorrect_match(match_idx + 1, input_line, match_line.strip())
221-
print_content(input_lines, match_lines, ignored_lines, hint_match=match_idx, hint_input=input_idx)
243+
print_content(
244+
input_lines,
245+
match_lines,
246+
ignored_lines,
247+
hint_match=match_idx,
248+
hint_input=input_idx,
249+
)
222250
sys.exit(1)
223251

224252

scripts/add_experimental_feature.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"""
2-
Copyright (C) 2023 Intel Corporation
2+
Copyright (C) 2023 Intel Corporation
33
4-
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
5-
See LICENSE.TXT
6-
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
5+
See LICENSE.TXT
6+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
77
88
"""
9+
910
import argparse
1011
import sys
1112
from util import makoWrite
1213
import re
1314
import subprocess
1415

16+
1517
def verify_kebab_case(input: str) -> bool:
1618
kebab_case_re = r"[a-z0-9]+(?:-[a-z0-9]+)*"
1719
pattern = re.compile(kebab_case_re)
@@ -37,19 +39,25 @@ def get_user_name_email_from_git_config():
3739
def main():
3840

3941
argParser = argparse.ArgumentParser()
40-
argParser.add_argument("name", help="must be lowercase and kebab case i.e. command-buffer", type=str)
41-
argParser.add_argument("--dry_run", help="run the script without generating any files", action='store_true')
42+
argParser.add_argument(
43+
"name", help="must be lowercase and kebab case i.e. command-buffer", type=str
44+
)
45+
argParser.add_argument(
46+
"--dry_run",
47+
help="run the script without generating any files",
48+
action="store_true",
49+
)
4250
args = argParser.parse_args()
4351

4452
if not verify_kebab_case(args.name):
4553
print("Name must be lowercase and kebab-case i.e. command-buffer.")
4654
sys.exit(1)
4755

4856
user_name, user_email = get_user_name_email_from_git_config()
49-
user = {'email':user_email, 'name': user_name}
57+
user = {"email": user_email, "name": user_name}
5058

5159
exp_feat_name = args.name
52-
60+
5361
out_yml_name = f"exp-{exp_feat_name}.yml"
5462
out_rst_name = f"EXP-{exp_feat_name.upper()}.rst"
5563

@@ -62,14 +70,15 @@ def main():
6270
makoWrite(yaml_template_path, out_yml_path, name=exp_feat_name)
6371
makoWrite(rst_template_path, out_rst_path, name=exp_feat_name, user=user)
6472

65-
66-
print(f"""\
73+
print(
74+
f"""\
6775
Successfully generated the template files needed for {exp_feat_name}.
6876
6977
You can now implement your feature in the following files:
7078
* {out_yml_name}
7179
* {out_rst_name}
72-
""")
80+
"""
81+
)
7382

7483

7584
if __name__ == "__main__":

scripts/benchmarks/benches/base.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,30 @@
1212
import urllib.request
1313
import tarfile
1414

15+
1516
class Benchmark:
1617
def __init__(self, directory, suite):
1718
self.directory = directory
1819
self.suite = suite
1920

2021
@staticmethod
2122
def get_adapter_full_path():
22-
for libs_dir_name in ['lib', 'lib64']:
23+
for libs_dir_name in ["lib", "lib64"]:
2324
adapter_path = os.path.join(
24-
options.ur, libs_dir_name, f"libur_adapter_{options.ur_adapter}.so")
25+
options.ur, libs_dir_name, f"libur_adapter_{options.ur_adapter}.so"
26+
)
2527
if os.path.isfile(adapter_path):
2628
return adapter_path
27-
assert False, \
28-
f"could not find adapter file {adapter_path} (and in similar lib paths)"
29+
assert (
30+
False
31+
), f"could not find adapter file {adapter_path} (and in similar lib paths)"
2932

3033
def run_bench(self, command, env_vars, ld_library=[], add_sycl=True):
3134
env_vars = env_vars.copy()
3235
if options.ur is not None:
3336
env_vars.update(
34-
{'UR_ADAPTERS_FORCE_LOAD': Benchmark.get_adapter_full_path()})
37+
{"UR_ADAPTERS_FORCE_LOAD": Benchmark.get_adapter_full_path()}
38+
)
3539

3640
env_vars.update(options.extra_env_vars)
3741

@@ -43,22 +47,22 @@ def run_bench(self, command, env_vars, ld_library=[], add_sycl=True):
4347
env_vars=env_vars,
4448
add_sycl=add_sycl,
4549
cwd=options.benchmark_cwd,
46-
ld_library=ld_libraries
50+
ld_library=ld_libraries,
4751
).stdout.decode()
4852

49-
def create_data_path(self, name, skip_data_dir = False):
53+
def create_data_path(self, name, skip_data_dir=False):
5054
if skip_data_dir:
5155
data_path = os.path.join(self.directory, name)
5256
else:
53-
data_path = os.path.join(self.directory, 'data', name)
57+
data_path = os.path.join(self.directory, "data", name)
5458
if options.rebuild and Path(data_path).exists():
5559
shutil.rmtree(data_path)
5660

5761
Path(data_path).mkdir(parents=True, exist_ok=True)
5862

5963
return data_path
6064

61-
def download(self, name, url, file, untar = False, unzip = False, skip_data_dir = False):
65+
def download(self, name, url, file, untar=False, unzip=False, skip_data_dir=False):
6266
self.data_path = self.create_data_path(name, skip_data_dir)
6367
return download(self.data_path, url, file, untar, unzip)
6468

@@ -83,6 +87,7 @@ def stddev_threshold(self):
8387
def get_suite_name(self) -> str:
8488
return self.suite.name()
8589

90+
8691
class Suite:
8792
def benchmarks(self) -> list[Benchmark]:
8893
raise NotImplementedError()

0 commit comments

Comments
 (0)