Skip to content

Commit d1a9393

Browse files
committed
[CI] Add ruff python checker. NFC
1 parent def60a9 commit d1a9393

39 files changed

+178
-142
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
sudo ./llvm.sh ${LLVM_VERSION}
4040
sudo apt-get install clang-format clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION}
4141
- run: flake8
42+
- run: ruff check
4243
- run: ./scripts/clang-format-diff.sh
4344
- name: clang-tidy
4445
run: |

.ruff.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
target-version = "py310"
2+
3+
exclude = [
4+
'third_party',
5+
'test/lit/lit.cfg.py',
6+
'test/spec/testsuite',
7+
]
8+
9+
[lint]
10+
select = [
11+
"ARG",
12+
"ASYNC",
13+
"B",
14+
"C4",
15+
"C90",
16+
"COM",
17+
"E",
18+
"F",
19+
"I",
20+
"PERF",
21+
"PIE",
22+
"PL",
23+
"UP",
24+
"W",
25+
"YTT",
26+
]
27+
28+
ignore = [
29+
"C901",
30+
"B006",
31+
"B011",
32+
"B023",
33+
"E501",
34+
"PERF401",
35+
"PLR0912",
36+
"PLR0913",
37+
"PLR0915",
38+
"PLR2004",
39+
"PLW0603",
40+
"PLW1510",
41+
"PLW2901",
42+
]

check.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,19 @@
1515
# limitations under the License.
1616

1717
import glob
18+
import io
1819
import os
20+
import queue
1921
import subprocess
2022
import sys
23+
import threading
2124
import unittest
2225
from collections import OrderedDict
2326
from concurrent.futures import ThreadPoolExecutor
24-
from pathlib import Path
25-
import queue
26-
import io
27-
import threading
2827
from functools import partial
28+
from pathlib import Path
2929

30-
from scripts.test import binaryenjs
31-
from scripts.test import lld
32-
from scripts.test import shared
33-
from scripts.test import support
34-
from scripts.test import wasm2js
35-
from scripts.test import wasm_opt
30+
from scripts.test import binaryenjs, lld, shared, support, wasm2js, wasm_opt
3631

3732

3833
def get_changelog_version():
@@ -55,7 +50,7 @@ def run_version_tests():
5550
not any(f.endswith(s) for s in not_executable_suffix) and
5651
any(os.path.basename(f).startswith(s) for s in executable_prefix)]
5752
executables = sorted(executables)
58-
assert len(executables)
53+
assert executables
5954

6055
changelog_version = get_changelog_version()
6156
for e in executables:

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
# Install with `pip3 install -r requirements-dev.txt`
55

66
flake8==7.3.0
7+
ruff==0.14.1
78
filecheck==0.0.22
89
lit==0.11.0.post1

scripts/auto_update_tests.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@
1919
import sys
2020
from collections import OrderedDict
2121

22-
from test import binaryenjs
23-
from test import lld
24-
from test import shared
25-
from test import support
26-
from test import wasm2js
27-
from test import wasm_opt
22+
from test import binaryenjs, lld, shared, support, wasm2js, wasm_opt
2823

2924

3025
def update_example_tests():

scripts/clusterfuzz/run.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
bundle_clusterfuzz.py.
2424
'''
2525

26-
import os
2726
import getopt
2827
import math
28+
import os
2929
import random
3030
import subprocess
3131
import sys
3232

33-
3433
# The V8 flags we put in the "fuzzer flags" files, which tell ClusterFuzz how to
3534
# run V8. By default we apply all staging flags.
3635
FUZZER_FLAGS = '--wasm-staging --experimental-wasm-custom-descriptors'
@@ -141,7 +140,7 @@ def get_wasm_contents(name, output_dir, extra_args=[]):
141140

142141
# wasm-opt may fail to run in rare cases (when the fuzzer emits code it
143142
# detects as invalid). Just try again in such a case.
144-
for attempt in range(0, 100):
143+
for attempt in range(100):
145144
# Generate random data.
146145
random_size = system_random.randint(1, MAX_RANDOM_SIZE)
147146
with open(input_data_file_path, 'wb') as file:
@@ -186,7 +185,7 @@ def get_wasm_contents(name, output_dir, extra_args=[]):
186185
global temp_files
187186
temp_files += [
188187
wasm_file_path,
189-
input_data_file_path
188+
input_data_file_path,
190189
]
191190

192191
# Convert to a string, and wrap into a typed array.

scripts/foreach.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616

1717
import os
18-
import sys
1918
import subprocess
19+
import sys
2020

2121
from test import support
2222

scripts/fuzz_opt.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,21 @@
2727
'''
2828

2929
import contextlib
30-
import os
3130
import difflib
3231
import json
3332
import math
34-
import shutil
35-
import subprocess
33+
import os
3634
import random
3735
import re
36+
import shutil
37+
import subprocess
3838
import sys
3939
import tarfile
4040
import time
4141
import traceback
4242
from os.path import abspath
4343

44-
from test import fuzzing
45-
from test import shared
46-
from test import support
47-
44+
from test import fuzzing, shared, support
4845

4946
assert sys.version_info >= (3, 10), 'requires Python 3.10'
5047

@@ -457,7 +454,7 @@ def compare(x, y, context, verbose=True):
457454
if verbose:
458455
raise Exception(context + " comparison error, expected to have '%s' == '%s', diff:\n\n%s" % (
459456
x, y,
460-
message
457+
message,
461458
))
462459
else:
463460
raise Exception(context + "\nDiff:\n\n%s" % (message))
@@ -1007,7 +1004,7 @@ def run_vms(self, wasm):
10071004

10081005
# compare between the vms on this specific input
10091006
num_vms = len(relevant_vms)
1010-
for i in range(0, num_vms):
1007+
for i in range(num_vms):
10111008
for j in range(i + 1, num_vms):
10121009
vm1 = relevant_vms[i]
10131010
vm2 = relevant_vms[j]
@@ -1036,8 +1033,8 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
10361033
if (b1 != b2):
10371034
run([in_bin('wasm-dis'), abspath('b1.wasm'), '-o', abspath('b1.wat')] + FEATURE_OPTS)
10381035
run([in_bin('wasm-dis'), abspath('b2.wasm'), '-o', abspath('b2.wat')] + FEATURE_OPTS)
1039-
t1 = open(abspath('b1.wat'), 'r').read()
1040-
t2 = open(abspath('b2.wat'), 'r').read()
1036+
t1 = open(abspath('b1.wat')).read()
1037+
t2 = open(abspath('b2.wat')).read()
10411038
compare(t1, t2, 'Output must be deterministic.', verbose=False)
10421039

10431040

@@ -1243,12 +1240,12 @@ def filter_exports(wasm, output, keep, keep_defaults=True):
12431240
graph = [{
12441241
'name': 'outside',
12451242
'reaches': [f'export-{export}' for export in keep],
1246-
'root': True
1243+
'root': True,
12471244
}]
12481245
for export in keep:
12491246
graph.append({
12501247
'name': f'export-{export}',
1251-
'export': export
1248+
'export': export,
12521249
})
12531250

12541251
with open('graph.json', 'w') as f:
@@ -1741,7 +1738,7 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
17411738
cmd = [shared.V8]
17421739
# The flags are given in the flags file - we do *not* use our normal
17431740
# flags here!
1744-
with open(flags_file, 'r') as f:
1741+
with open(flags_file) as f:
17451742
flags = f.read()
17461743
cmd += flags.split(' ')
17471744
# Get V8's extra fuzzing flags, the same as the ClusterFuzz runner does

scripts/fuzz_passes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Other parameters after the first are used when calling the program.
2626
'''
2727

28-
from __future__ import print_function
2928

3029
import os
3130
import random

scripts/fuzz_passes_wast.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
Usage: Provide the filename of the wast.
2323
'''
2424

25-
from __future__ import print_function
2625

2726
import os
2827
import random

0 commit comments

Comments
 (0)