mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
build: upgrade Python linter ruff, add rules ASYNC,PERF
PR-URL: https://github.com/nodejs/node/pull/59984 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
parent
200fe9e7f4
commit
0fb040603b
5
Makefile
5
Makefile
|
|
@ -1565,8 +1565,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)")
|
||||
|
|
@ -1576,7 +1576,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
|
||||
|
|
|
|||
|
|
@ -1300,7 +1300,7 @@ def check_compiler(o):
|
|||
print_verbose(f"Detected {'Apple ' if is_apple else ''}{'clang ' if is_clang else ''}C++ compiler (CXX={CXX}) version: {version_str}")
|
||||
if not ok:
|
||||
warn(f'failed to autodetect C++ compiler version (CXX={CXX})')
|
||||
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):
|
||||
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):
|
||||
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 ''}")
|
||||
|
||||
ok, is_clang, clang_version, gcc_version, is_apple = try_check_compiler(CC, 'c')
|
||||
|
|
|
|||
|
|
@ -11,11 +11,13 @@ target-version = "py39"
|
|||
|
||||
[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",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -160,9 +160,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):
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -817,7 +817,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,
|
||||
|
|
@ -924,7 +924,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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user