Skip to content

Commit 0fb0406

Browse files
authored
build: upgrade Python linter ruff, add rules ASYNC,PERF
PR-URL: #59984 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
1 parent 200fe9e commit 0fb0406

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,8 @@ cpplint: lint-cpp
15651565
# Try with '--system' if it fails without; the system may have set '--user'
15661566
lint-py-build: ## Build resources needed to lint python files.
15671567
$(info Pip installing ruff on $(shell $(PYTHON) --version)...)
1568-
$(PYTHON) -m pip install --upgrade --target tools/pip/site-packages ruff==0.6.5 || \
1569-
$(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff==0.6.5
1568+
$(PYTHON) -m pip install --upgrade --target tools/pip/site-packages ruff==0.13.1 || \
1569+
$(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff==0.13.1
15701570

15711571
.PHONY: lint-py lint-py-fix lint-py-fix-unsafe
15721572
ifneq ("","$(wildcard tools/pip/site-packages/ruff)")
@@ -1576,7 +1576,6 @@ lint-py:
15761576
tools/pip/site-packages/bin/ruff check .
15771577
lint-py-fix:
15781578
tools/pip/site-packages/bin/ruff check . --fix
1579-
15801579
lint-py-fix-unsafe:
15811580
tools/pip/site-packages/bin/ruff check . --fix --unsafe-fixes
15821581
else

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ def check_compiler(o):
13001300
print_verbose(f"Detected {'Apple ' if is_apple else ''}{'clang ' if is_clang else ''}C++ compiler (CXX={CXX}) version: {version_str}")
13011301
if not ok:
13021302
warn(f'failed to autodetect C++ compiler version (CXX={CXX})')
1303-
elif (is_apple and clang_version < (17, 0, 0) or not is_apple and clang_version < (19, 1, 0)) if is_clang else gcc_version < (12, 2, 0):
1303+
elif ((is_apple and clang_version < (17, 0, 0)) or (not is_apple and clang_version < (19, 1, 0))) if is_clang else gcc_version < (12, 2, 0):
13041304
warn(f"C++ compiler (CXX={CXX}, {version_str}) too old, need g++ 12.2.0 or clang++ 19.1.0{' or Apple clang++ 17.0.0' if is_apple else ''}")
13051305

13061306
ok, is_clang, clang_version, gcc_version, is_apple = try_check_compiler(CC, 'c')

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ target-version = "py39"
1111

1212
[tool.ruff.lint]
1313
select = [
14+
"ASYNC", # flake8-async
1415
"C90", # McCabe cyclomatic complexity
1516
"E", # pycodestyle
1617
"F", # Pyflakes
1718
"ICN", # flake8-import-conventions
1819
"INT", # flake8-gettext
20+
"PERF", # flake8-performance
1921
"PLC", # Pylint conventions
2022
"PLE", # Pylint errors
2123
"PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements
@@ -32,6 +34,7 @@ ignore = [
3234
"E401",
3335
"E402",
3436
"E7",
37+
"PLC0415",
3538
"RUF005",
3639
]
3740

test/testpy/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ def SelectTest(name):
160160
result = []
161161
for subpath in os.listdir(path):
162162
if os.path.isdir(os.path.join(path, subpath)):
163-
for f in os.listdir(os.path.join(path, subpath)):
164-
if SelectTest(f):
165-
result.append([subpath, f[:-3]])
163+
result.extend([subpath, f[:-3]] for f in os.listdir(os.path.join(path, subpath)) if SelectTest(f))
166164
return result
167165

168166
def ListTests(self, current_path, path, arch, mode):

test/tools/test_checkimports.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CheckImportsTest(unittest.TestCase):
2828
'test', 'fixtures', 'tools', 'checkimports')
2929

3030
def test_unused_and_unsorted(self):
31-
with captured_output() as (out, err):
31+
with captured_output() as (out, _err):
3232
self.assertEqual(is_valid(path.join(self.fixturesDir, 'invalid.cc')),
3333
False)
3434
output = out.getvalue()
@@ -42,21 +42,21 @@ def test_unused_and_unsorted(self):
4242
output);
4343

4444
def test_unused_complex(self):
45-
with captured_output() as (out, err):
45+
with captured_output() as (out, _err):
4646
self.assertEqual(is_valid(path.join(self.fixturesDir, 'maybe.cc')),
4747
False)
4848
output = out.getvalue()
4949
self.assertIn('does not use "Local"', output);
5050

5151
def test_unused_simple(self):
52-
with captured_output() as (out, err):
52+
with captured_output() as (out, _err):
5353
self.assertEqual(is_valid(path.join(self.fixturesDir, 'unused.cc')),
5454
False)
5555
output = out.getvalue()
5656
self.assertIn('does not use "Context"', output);
5757

5858
def test_unsorted(self):
59-
with captured_output() as (out, err):
59+
with captured_output() as (out, _err):
6060
self.assertEqual(is_valid(path.join(self.fixturesDir, 'unsorted.cc')),
6161
False)
6262
output = out.getvalue()
@@ -67,7 +67,7 @@ def test_unsorted(self):
6767
output);
6868

6969
def test_valid(self):
70-
with captured_output() as (out, err):
70+
with captured_output() as (out, _err):
7171
self.assertEqual(is_valid(path.join(self.fixturesDir, 'valid.cc')),
7272
True)
7373
output = out.getvalue()

tools/generate_config_gypi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def main():
9595
default='//node')
9696
parser.add_argument('--dep-file', help='path to an optional dep file',
9797
default=None)
98-
args, unknown_args = parser.parse_known_args()
98+
args, _unknown_args = parser.parse_known_args()
9999

100100
config = get_gn_config(args.out_dir)
101101
v8_config = get_v8_config(args.out_dir, args.node_gn_path)

tools/icu/icutrim.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,17 @@ def removeList(count=0):
339339
removeList(1)
340340

341341
# now, fixup res_index, one at a time
342-
for tree in trees:
342+
for tree, value in trees.items():
343343
# skip trees that don't have res_index
344-
if "hasIndex" not in trees[tree]:
344+
if "hasIndex" not in value:
345345
continue
346346
treebunddir = options.tmpdir
347-
if(trees[tree]["treeprefix"]):
348-
treebunddir = os.path.join(treebunddir, trees[tree]["treeprefix"])
347+
if(value["treeprefix"]):
348+
treebunddir = os.path.join(treebunddir, value["treeprefix"])
349349
if not (os.path.isdir(treebunddir)):
350350
os.mkdir(treebunddir)
351351
treebundres = os.path.join(treebunddir,RES_INDX)
352352
treebundtxt = "%s.txt" % (treebundres[0:-4])
353353
runcmd("iculslocs", "-i %s -N %s -T %s -b %s" % (outfile, dataname, tree, treebundtxt))
354354
runcmd("genrb","-d %s -s %s res_index.txt" % (treebunddir, treebunddir))
355-
runcmd("icupkg","-s %s -a %s%s %s" % (options.tmpdir, trees[tree]["treeprefix"], RES_INDX, outfile))
355+
runcmd("icupkg","-s %s -a %s%s %s" % (options.tmpdir, value["treeprefix"], RES_INDX, outfile))

tools/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def try_copy(options, path, dest):
7373
return shutil.copy2(source_path, target_path)
7474

7575
def try_remove(options, path, dest):
76-
source_path, target_path = mkpaths(options, path, dest)
76+
_source_path, target_path = mkpaths(options, path, dest)
7777
if not options.silent:
7878
print('removing %s' % target_path)
7979
try_unlink(target_path)

tools/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ def setResourceLimits():
817817
else:
818818
preexec_fn = setMaxVirtualMemory
819819

820-
(process, exit_code, timed_out) = RunProcess(
820+
(_process, exit_code, timed_out) = RunProcess(
821821
context,
822822
timeout,
823823
args = args,
@@ -924,7 +924,7 @@ def GetBuildRequirements(self, path, context):
924924
return result
925925

926926
def ListTests(self, current_path, path, context, arch, mode):
927-
(name, rest) = CarCdr(path)
927+
(name, _rest) = CarCdr(path)
928928
result = [ ]
929929
for test in self.tests_repos:
930930
test_name = test.GetName()

0 commit comments

Comments
 (0)