From 9408c4459fd70d556fb21ee782bac792f611949e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 8 Oct 2025 09:37:31 +0200 Subject: [PATCH] build: upgrade Python linter ruff, add rules ASYNC,PERF PR-URL: https://github.com/nodejs/node/pull/59984 Reviewed-By: Yagiz Nizipli Reviewed-By: Luigi Pinca Reviewed-By: Chengzhong Wu Reviewed-By: Moshe Atlow --- Makefile | 5 ++--- pyproject.toml | 3 +++ test/testpy/__init__.py | 4 +--- test/tools/test_checkimports.py | 10 +++++----- tools/generate_config_gypi.py | 2 +- tools/icu/icutrim.py | 10 +++++----- tools/install.py | 2 +- tools/test.py | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index d54f61a372b..6b60818ec68 100644 --- a/Makefile +++ b/Makefile @@ -1583,8 +1583,8 @@ cpplint: lint-cpp # Try with '--system' if it fails without; the system may have set '--user' lint-py-build: ## Build resources needed to lint python files. $(info Pip installing ruff on $(shell $(PYTHON) --version)...) - $(PYTHON) -m pip install --upgrade --target tools/pip/site-packages ruff==0.6.5 || \ - $(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff==0.6.5 + $(PYTHON) -m pip install --upgrade --target tools/pip/site-packages ruff==0.13.1 || \ + $(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff==0.13.1 .PHONY: lint-py lint-py-fix lint-py-fix-unsafe ifneq ("","$(wildcard tools/pip/site-packages/ruff)") @@ -1594,7 +1594,6 @@ lint-py: tools/pip/site-packages/bin/ruff check . lint-py-fix: tools/pip/site-packages/bin/ruff check . --fix - lint-py-fix-unsafe: tools/pip/site-packages/bin/ruff check . --fix --unsafe-fixes else diff --git a/pyproject.toml b/pyproject.toml index 45f540bd151..6e9cc6aeece 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,11 +11,13 @@ target-version = "py38" [tool.ruff.lint] select = [ + "ASYNC", # flake8-async "C90", # McCabe cyclomatic complexity "E", # pycodestyle "F", # Pyflakes "ICN", # flake8-import-conventions "INT", # flake8-gettext + "PERF", # flake8-performance "PLC", # Pylint conventions "PLE", # Pylint errors "PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements @@ -32,6 +34,7 @@ ignore = [ "E401", "E402", "E7", + "PLC0415", "RUF005", ] diff --git a/test/testpy/__init__.py b/test/testpy/__init__.py index b5d9ea726ff..0f0c15ff577 100644 --- a/test/testpy/__init__.py +++ b/test/testpy/__init__.py @@ -147,9 +147,7 @@ class AddonTestConfiguration(SimpleTestConfiguration): result = [] for subpath in os.listdir(path): if os.path.isdir(os.path.join(path, subpath)): - for f in os.listdir(os.path.join(path, subpath)): - if SelectTest(f): - result.append([subpath, f[:-3]]) + result.extend([subpath, f[:-3]] for f in os.listdir(os.path.join(path, subpath)) if SelectTest(f)) return result def ListTests(self, current_path, path, arch, mode): diff --git a/test/tools/test_checkimports.py b/test/tools/test_checkimports.py index 6e8e17cc3f9..fd28542e453 100644 --- a/test/tools/test_checkimports.py +++ b/test/tools/test_checkimports.py @@ -28,7 +28,7 @@ class CheckImportsTest(unittest.TestCase): 'test', 'fixtures', 'tools', 'checkimports') def test_unused_and_unsorted(self): - with captured_output() as (out, err): + with captured_output() as (out, _err): self.assertEqual(is_valid(path.join(self.fixturesDir, 'invalid.cc')), False) output = out.getvalue() @@ -42,21 +42,21 @@ class CheckImportsTest(unittest.TestCase): output); def test_unused_complex(self): - with captured_output() as (out, err): + with captured_output() as (out, _err): self.assertEqual(is_valid(path.join(self.fixturesDir, 'maybe.cc')), False) output = out.getvalue() self.assertIn('does not use "Local"', output); def test_unused_simple(self): - with captured_output() as (out, err): + with captured_output() as (out, _err): self.assertEqual(is_valid(path.join(self.fixturesDir, 'unused.cc')), False) output = out.getvalue() self.assertIn('does not use "Context"', output); def test_unsorted(self): - with captured_output() as (out, err): + with captured_output() as (out, _err): self.assertEqual(is_valid(path.join(self.fixturesDir, 'unsorted.cc')), False) output = out.getvalue() @@ -67,7 +67,7 @@ class CheckImportsTest(unittest.TestCase): output); def test_valid(self): - with captured_output() as (out, err): + with captured_output() as (out, _err): self.assertEqual(is_valid(path.join(self.fixturesDir, 'valid.cc')), True) output = out.getvalue() diff --git a/tools/generate_config_gypi.py b/tools/generate_config_gypi.py index ac8edb6896a..abd11e1dbda 100755 --- a/tools/generate_config_gypi.py +++ b/tools/generate_config_gypi.py @@ -95,7 +95,7 @@ def main(): default='//node') parser.add_argument('--dep-file', help='path to an optional dep file', default=None) - args, unknown_args = parser.parse_known_args() + args, _unknown_args = parser.parse_known_args() config = get_gn_config(args.out_dir) v8_config = get_v8_config(args.out_dir, args.node_gn_path) diff --git a/tools/icu/icutrim.py b/tools/icu/icutrim.py index 0ae8c23319d..4441550df09 100755 --- a/tools/icu/icutrim.py +++ b/tools/icu/icutrim.py @@ -339,17 +339,17 @@ def removeList(count=0): removeList(1) # now, fixup res_index, one at a time -for tree in trees: +for tree, value in trees.items(): # skip trees that don't have res_index - if "hasIndex" not in trees[tree]: + if "hasIndex" not in value: continue treebunddir = options.tmpdir - if(trees[tree]["treeprefix"]): - treebunddir = os.path.join(treebunddir, trees[tree]["treeprefix"]) + if(value["treeprefix"]): + treebunddir = os.path.join(treebunddir, value["treeprefix"]) if not (os.path.isdir(treebunddir)): os.mkdir(treebunddir) treebundres = os.path.join(treebunddir,RES_INDX) treebundtxt = "%s.txt" % (treebundres[0:-4]) runcmd("iculslocs", "-i %s -N %s -T %s -b %s" % (outfile, dataname, tree, treebundtxt)) runcmd("genrb","-d %s -s %s res_index.txt" % (treebunddir, treebunddir)) - runcmd("icupkg","-s %s -a %s%s %s" % (options.tmpdir, trees[tree]["treeprefix"], RES_INDX, outfile)) + runcmd("icupkg","-s %s -a %s%s %s" % (options.tmpdir, value["treeprefix"], RES_INDX, outfile)) diff --git a/tools/install.py b/tools/install.py index 8797b59e59c..a619fd17b16 100755 --- a/tools/install.py +++ b/tools/install.py @@ -73,7 +73,7 @@ def try_copy(options, path, dest): return shutil.copy2(source_path, target_path) def try_remove(options, path, dest): - source_path, target_path = mkpaths(options, path, dest) + _source_path, target_path = mkpaths(options, path, dest) if not options.silent: print('removing %s' % target_path) try_unlink(target_path) diff --git a/tools/test.py b/tools/test.py index 9be8b5d2e69..9a3561b7464 100755 --- a/tools/test.py +++ b/tools/test.py @@ -808,7 +808,7 @@ def Execute(args, context, timeout=None, env=None, disable_core_files=False, else: preexec_fn = setMaxVirtualMemory - (process, exit_code, timed_out) = RunProcess( + (_process, exit_code, timed_out) = RunProcess( context, timeout, args = args, @@ -915,7 +915,7 @@ class LiteralTestSuite(TestSuite): return result def ListTests(self, current_path, path, context, arch, mode): - (name, rest) = CarCdr(path) + (name, _rest) = CarCdr(path) result = [ ] for test in self.tests_repos: test_name = test.GetName()