Skip to content

Commit ab03fa2

Browse files
authored
[CodeStyle] black -> ruff format migration - part 40 (#74794)
1 parent 15d8a04 commit ab03fa2

File tree

6 files changed

+66
-64
lines changed

6 files changed

+66
-64
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ repos:
107107
108108
# | test/[m-z].+
109109
110-
# | tools/.+
110+
| tools/.+
111111
)$
112112
- repo: https://github.com/astral-sh/ruff-pre-commit
113113
rev: v0.12.0
@@ -163,7 +163,7 @@ repos:
163163
164164
| test/[m-z].+
165165
166-
| tools/.+
166+
# | tools/.+
167167
)$
168168
# For C++ files
169169
- repo: local

tools/check_op_benchmark_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def compare_benchmark_result(
115115
develop_speed = develop_result.get("speed")
116116
pr_speed = pr_result.get("speed")
117117

118-
assert type(develop_speed) == type(
119-
pr_speed
120-
), "The types of comparison results need to be consistent."
118+
assert type(develop_speed) == type(pr_speed), (
119+
"The types of comparison results need to be consistent."
120+
)
121121

122122
if isinstance(develop_speed, dict) and isinstance(pr_speed, dict):
123123
if check_speed_result(case_name, develop_speed, pr_speed, pr_result):

tools/check_op_desc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,17 @@ def compare_op_desc(origin_op_desc, new_op_desc):
300300
desc_error_message.setdefault(op_type, {})[ATTRS] = attrs_diff
301301

302302
if ins_version_errors:
303-
version_error_message.setdefault(op_type, {})[
304-
INPUTS
305-
] = ins_version_errors
303+
version_error_message.setdefault(op_type, {})[INPUTS] = (
304+
ins_version_errors
305+
)
306306
if outs_version_errors:
307-
version_error_message.setdefault(op_type, {})[
308-
OUTPUTS
309-
] = outs_version_errors
307+
version_error_message.setdefault(op_type, {})[OUTPUTS] = (
308+
outs_version_errors
309+
)
310310
if attrs_version_errors:
311-
version_error_message.setdefault(op_type, {})[
312-
ATTRS
313-
] = attrs_version_errors
311+
version_error_message.setdefault(op_type, {})[ATTRS] = (
312+
attrs_version_errors
313+
)
314314

315315
return desc_error_message, version_error_message
316316

tools/gen_pybind11_stub.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ def parse_input_and_attr(
525525
inputs = {'names': [], 'input_info': {}}
526526
attrs = {'names': [], 'attr_info': {}}
527527
args_str = args_config.strip()
528-
assert args_str.startswith('(') and args_str.endswith(
529-
')'
530-
), f"Args declaration should start with '(' and end with ')', please check the args of {api_name} in yaml."
528+
assert args_str.startswith('(') and args_str.endswith(')'), (
529+
f"Args declaration should start with '(' and end with ')', please check the args of {api_name} in yaml."
530+
)
531531
args_str = args_str[1:-1]
532532
pattern = re.compile(r',(?![^{]*\})') # support int[] a={1,3}
533533
args_list = re.split(pattern, args_str.strip())
@@ -541,12 +541,12 @@ def parse_input_and_attr(
541541
for in_type_symbol, in_type in INPUT_TYPES_MAP.items():
542542
if type_and_name[0] == in_type_symbol:
543543
input_name = type_and_name[1].strip()
544-
assert (
545-
len(input_name) > 0
546-
), f"The input tensor name should not be empty. Please check the args of {api_name} in yaml."
547-
assert (
548-
len(attrs['names']) == 0
549-
), f"The input Tensor should appear before attributes. please check the position of {api_name}:input({input_name}) in yaml"
544+
assert len(input_name) > 0, (
545+
f"The input tensor name should not be empty. Please check the args of {api_name} in yaml."
546+
)
547+
assert len(attrs['names']) == 0, (
548+
f"The input Tensor should appear before attributes. please check the position of {api_name}:input({input_name}) in yaml"
549+
)
550550

551551
if input_name in optional_vars:
552552
in_type = OPTIONAL_TYPES_TRANS[in_type_symbol]
@@ -562,9 +562,9 @@ def parse_input_and_attr(
562562
for attr_type_symbol, attr_type in ATTR_TYPES_MAP.items():
563563
if type_and_name[0] == attr_type_symbol:
564564
attr_name = item[len(attr_type_symbol) :].strip()
565-
assert (
566-
len(attr_name) > 0
567-
), f"The attribute name should not be empty. Please check the args of {api_name} in yaml."
565+
assert len(attr_name) > 0, (
566+
f"The attribute name should not be empty. Please check the args of {api_name} in yaml."
567+
)
568568
default_value = None
569569
if '=' in attr_name:
570570
attr_infos = attr_name.split('=')
@@ -589,14 +589,14 @@ def parse_output_item(output_item):
589589
r"(?P<out_type>[a-zA-Z0-9_[\]]+)\s*(?P<name>\([a-zA-Z0-9_@]+\))?\s*(?P<expr>\{[^\}]+\})?",
590590
output_item,
591591
)
592-
assert (
593-
result is not None
594-
), f"{api_name} : the output config parse error."
592+
assert result is not None, (
593+
f"{api_name} : the output config parse error."
594+
)
595595
out_type = result.group('out_type')
596-
assert (
597-
out_type in OUTPUT_TYPE_MAP
598-
), f"{api_name} : Output type error: the output type only support Tensor and Tensor[], \
596+
assert out_type in OUTPUT_TYPE_MAP, (
597+
f"{api_name} : Output type error: the output type only support Tensor and Tensor[], \
599598
but now is {out_type}."
599+
)
600600

601601
out_name = (
602602
'out'

tools/gen_ut_cmakelists.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ def _process_archs(arch):
9999
for a in arch.split(";"):
100100
if '' == a:
101101
continue
102-
assert a in [
103-
"GPU",
104-
"ROCM",
105-
"XPU",
106-
], f"""Supported arch options are "GPU", "ROCM", and "XPU", but the options is {a}"""
102+
assert a in ["GPU", "ROCM", "XPU"], (
103+
f"""Supported arch options are "GPU", "ROCM", and "XPU", but the options is {a}"""
104+
)
107105
archs += "WITH_" + a.upper() + " OR "
108106
arch = "(" + archs[:-4] + ")"
109107
else:
@@ -127,11 +125,9 @@ def _process_os(os_):
127125
if len(os_) > 0:
128126
os_ = os_.upper()
129127
for p in os_.split(';'):
130-
assert p in [
131-
"WIN32",
132-
"APPLE",
133-
"LINUX",
134-
], f"""Supported os options are 'WIN32', 'APPLE' and 'LINUX', but the options is {p}"""
128+
assert p in ["WIN32", "APPLE", "LINUX"], (
129+
f"""Supported os options are 'WIN32', 'APPLE' and 'LINUX', but the options is {p}"""
130+
)
135131
os_ = os_.replace(";", " OR ")
136132
os_ = "(" + os_ + ")"
137133
else:
@@ -146,7 +142,9 @@ def _process_run_serial(run_serial):
146142
"1",
147143
"0",
148144
"",
149-
], f"""the value of run_serial must be one of 0, 1 or empty. But this value is {rs}"""
145+
], (
146+
f"""the value of run_serial must be one of 0, 1 or empty. But this value is {rs}"""
147+
)
150148
if rs == "":
151149
return ""
152150
return rs
@@ -175,9 +173,9 @@ def _process_name(name, curdir):
175173
)
176174
filepath_prefix = os.path.join(curdir, name)
177175
suffix = [".py", ".sh"]
178-
assert _file_with_extension(
179-
filepath_prefix, suffix
180-
), f""" Please ensure the test file with the prefix '{filepath_prefix}' and one of the suffix {suffix} exists, because you specified a unittest named '{name}'"""
176+
assert _file_with_extension(filepath_prefix, suffix), (
177+
f""" Please ensure the test file with the prefix '{filepath_prefix}' and one of the suffix {suffix} exists, because you specified a unittest named '{name}'"""
178+
)
181179

182180
return name
183181

@@ -238,7 +236,9 @@ def process_dist_port_num(self, port_num):
238236
re.compile("^[0-9]+$").search(port_num)
239237
and int(port_num) > 0
240238
or port_num.strip() == ""
241-
), f"""port_num must be format as a positive integer or empty, but this port_num is '{port_num}'"""
239+
), (
240+
f"""port_num must be format as a positive integer or empty, but this port_num is '{port_num}'"""
241+
)
242242
port_num = port_num.strip()
243243
if len(port_num) == 0:
244244
return 0
@@ -272,7 +272,9 @@ def _init_dist_ut_ports_from_cmakefile(self, cmake_file_name):
272272

273273
# match right tests name format, the name must start with 'test_' followed by at least one char of
274274
# '0-9'. 'a-z'. 'A-Z' or '_'
275-
assert re.compile("^test_[0-9a-zA-Z_]+").search(
275+
assert re.compile(
276+
"^test_[0-9a-zA-Z_]+"
277+
).search(
276278
name
277279
), f'''we found a test for initial the latest dist_port but the test name '{name}' seems to be wrong
278280
at line {k - 1}, in file {cmake_file_name}
@@ -349,9 +351,9 @@ def parse_assigned_dist_ut_ports(self, current_work_dir, depth=0):
349351
if name == self.last_test_name:
350352
found = True
351353
break
352-
assert (
353-
found
354-
), f"no such test named '{self.last_test_name}' in file '{self.last_test_cmake_file}'"
354+
assert found, (
355+
f"no such test named '{self.last_test_name}' in file '{self.last_test_cmake_file}'"
356+
)
355357
if launcher[-2:] == ".sh":
356358
self.process_dist_port_num(num_port)
357359

@@ -485,9 +487,9 @@ def _parse_line(self, line, curdir):
485487
try:
486488
run_type = _process_run_type(run_type)
487489
except Exception as e:
488-
assert (
489-
run_type.strip() == ""
490-
), f"{e}\nIf use test_runner.py, the run_type can be ''"
490+
assert run_type.strip() == "", (
491+
f"{e}\nIf use test_runner.py, the run_type can be ''"
492+
)
491493
cmd += f'''if({archs} AND {os_})
492494
py_test_modules(
493495
{name}
@@ -580,7 +582,9 @@ def _gen_cmakelists(self, current_work_dir, depth=0):
580582
assert (
581583
f"{current_work_dir}/CMakeLists.txt"
582584
not in self.modified_or_created_files
583-
), f"the file {current_work_dir}/CMakeLists.txt are modified twice, which may cause some error"
585+
), (
586+
f"the file {current_work_dir}/CMakeLists.txt are modified twice, which may cause some error"
587+
)
584588
self.modified_or_created_files.append(
585589
f"{current_work_dir}/CMakeLists.txt"
586590
)
@@ -630,15 +634,15 @@ def _gen_cmakelists(self, current_work_dir, depth=0):
630634
)
631635
args = parser.parse_args()
632636

633-
assert not (
634-
len(args.files) == 0 and len(args.dirpaths) == 0
635-
), "You must provide at least one file or dirpath"
637+
assert not (len(args.files) == 0 and len(args.dirpaths) == 0), (
638+
"You must provide at least one file or dirpath"
639+
)
636640
current_work_dirs = []
637641
if len(args.files) >= 1:
638642
for p in args.files:
639-
assert (
640-
os.path.basename(p) == "testslist.csv"
641-
), "you must input file named testslist.csv"
643+
assert os.path.basename(p) == "testslist.csv", (
644+
"you must input file named testslist.csv"
645+
)
642646
current_work_dirs = current_work_dirs + [
643647
os.path.dirname(file) for file in args.files
644648
]

tools/test_check_pr_approval.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def setUp(self):
6868
"author_association": "CONTRIBUTOR"
6969
}
7070
]
71-
""".encode(
72-
self.codeset
73-
)
71+
""".encode(self.codeset)
7472

7573
def test_ids(self):
7674
cmd = [sys.executable, 'check_pr_approval.py', '1', '26408901']

0 commit comments

Comments
 (0)