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'
|
# Try with '--system' if it fails without; the system may have set '--user'
|
||||||
lint-py-build: ## Build resources needed to lint python files.
|
lint-py-build: ## Build resources needed to lint python files.
|
||||||
$(info Pip installing ruff on $(shell $(PYTHON) --version)...)
|
$(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 --target tools/pip/site-packages ruff==0.13.1 || \
|
||||||
$(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff==0.6.5
|
$(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
|
.PHONY: lint-py lint-py-fix lint-py-fix-unsafe
|
||||||
ifneq ("","$(wildcard tools/pip/site-packages/ruff)")
|
ifneq ("","$(wildcard tools/pip/site-packages/ruff)")
|
||||||
|
|
@ -1576,7 +1576,6 @@ lint-py:
|
||||||
tools/pip/site-packages/bin/ruff check .
|
tools/pip/site-packages/bin/ruff check .
|
||||||
lint-py-fix:
|
lint-py-fix:
|
||||||
tools/pip/site-packages/bin/ruff check . --fix
|
tools/pip/site-packages/bin/ruff check . --fix
|
||||||
|
|
||||||
lint-py-fix-unsafe:
|
lint-py-fix-unsafe:
|
||||||
tools/pip/site-packages/bin/ruff check . --fix --unsafe-fixes
|
tools/pip/site-packages/bin/ruff check . --fix --unsafe-fixes
|
||||||
else
|
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}")
|
print_verbose(f"Detected {'Apple ' if is_apple else ''}{'clang ' if is_clang else ''}C++ compiler (CXX={CXX}) version: {version_str}")
|
||||||
if not ok:
|
if not ok:
|
||||||
warn(f'failed to autodetect C++ compiler version (CXX={CXX})')
|
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 ''}")
|
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')
|
ok, is_clang, clang_version, gcc_version, is_apple = try_check_compiler(CC, 'c')
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,13 @@ target-version = "py39"
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = [
|
select = [
|
||||||
|
"ASYNC", # flake8-async
|
||||||
"C90", # McCabe cyclomatic complexity
|
"C90", # McCabe cyclomatic complexity
|
||||||
"E", # pycodestyle
|
"E", # pycodestyle
|
||||||
"F", # Pyflakes
|
"F", # Pyflakes
|
||||||
"ICN", # flake8-import-conventions
|
"ICN", # flake8-import-conventions
|
||||||
"INT", # flake8-gettext
|
"INT", # flake8-gettext
|
||||||
|
"PERF", # flake8-performance
|
||||||
"PLC", # Pylint conventions
|
"PLC", # Pylint conventions
|
||||||
"PLE", # Pylint errors
|
"PLE", # Pylint errors
|
||||||
"PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements
|
"PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements
|
||||||
|
|
@ -32,6 +34,7 @@ ignore = [
|
||||||
"E401",
|
"E401",
|
||||||
"E402",
|
"E402",
|
||||||
"E7",
|
"E7",
|
||||||
|
"PLC0415",
|
||||||
"RUF005",
|
"RUF005",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,9 +160,7 @@ class AddonTestConfiguration(SimpleTestConfiguration):
|
||||||
result = []
|
result = []
|
||||||
for subpath in os.listdir(path):
|
for subpath in os.listdir(path):
|
||||||
if os.path.isdir(os.path.join(path, subpath)):
|
if os.path.isdir(os.path.join(path, subpath)):
|
||||||
for f in os.listdir(os.path.join(path, subpath)):
|
result.extend([subpath, f[:-3]] for f in os.listdir(os.path.join(path, subpath)) if SelectTest(f))
|
||||||
if SelectTest(f):
|
|
||||||
result.append([subpath, f[:-3]])
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def ListTests(self, current_path, path, arch, mode):
|
def ListTests(self, current_path, path, arch, mode):
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class CheckImportsTest(unittest.TestCase):
|
||||||
'test', 'fixtures', 'tools', 'checkimports')
|
'test', 'fixtures', 'tools', 'checkimports')
|
||||||
|
|
||||||
def test_unused_and_unsorted(self):
|
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')),
|
self.assertEqual(is_valid(path.join(self.fixturesDir, 'invalid.cc')),
|
||||||
False)
|
False)
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
|
|
@ -42,21 +42,21 @@ class CheckImportsTest(unittest.TestCase):
|
||||||
output);
|
output);
|
||||||
|
|
||||||
def test_unused_complex(self):
|
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')),
|
self.assertEqual(is_valid(path.join(self.fixturesDir, 'maybe.cc')),
|
||||||
False)
|
False)
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
self.assertIn('does not use "Local"', output);
|
self.assertIn('does not use "Local"', output);
|
||||||
|
|
||||||
def test_unused_simple(self):
|
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')),
|
self.assertEqual(is_valid(path.join(self.fixturesDir, 'unused.cc')),
|
||||||
False)
|
False)
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
self.assertIn('does not use "Context"', output);
|
self.assertIn('does not use "Context"', output);
|
||||||
|
|
||||||
def test_unsorted(self):
|
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')),
|
self.assertEqual(is_valid(path.join(self.fixturesDir, 'unsorted.cc')),
|
||||||
False)
|
False)
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
|
|
@ -67,7 +67,7 @@ class CheckImportsTest(unittest.TestCase):
|
||||||
output);
|
output);
|
||||||
|
|
||||||
def test_valid(self):
|
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')),
|
self.assertEqual(is_valid(path.join(self.fixturesDir, 'valid.cc')),
|
||||||
True)
|
True)
|
||||||
output = out.getvalue()
|
output = out.getvalue()
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ def main():
|
||||||
default='//node')
|
default='//node')
|
||||||
parser.add_argument('--dep-file', help='path to an optional dep file',
|
parser.add_argument('--dep-file', help='path to an optional dep file',
|
||||||
default=None)
|
default=None)
|
||||||
args, unknown_args = parser.parse_known_args()
|
args, _unknown_args = parser.parse_known_args()
|
||||||
|
|
||||||
config = get_gn_config(args.out_dir)
|
config = get_gn_config(args.out_dir)
|
||||||
v8_config = get_v8_config(args.out_dir, args.node_gn_path)
|
v8_config = get_v8_config(args.out_dir, args.node_gn_path)
|
||||||
|
|
|
||||||
|
|
@ -339,17 +339,17 @@ def removeList(count=0):
|
||||||
removeList(1)
|
removeList(1)
|
||||||
|
|
||||||
# now, fixup res_index, one at a time
|
# 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
|
# skip trees that don't have res_index
|
||||||
if "hasIndex" not in trees[tree]:
|
if "hasIndex" not in value:
|
||||||
continue
|
continue
|
||||||
treebunddir = options.tmpdir
|
treebunddir = options.tmpdir
|
||||||
if(trees[tree]["treeprefix"]):
|
if(value["treeprefix"]):
|
||||||
treebunddir = os.path.join(treebunddir, trees[tree]["treeprefix"])
|
treebunddir = os.path.join(treebunddir, value["treeprefix"])
|
||||||
if not (os.path.isdir(treebunddir)):
|
if not (os.path.isdir(treebunddir)):
|
||||||
os.mkdir(treebunddir)
|
os.mkdir(treebunddir)
|
||||||
treebundres = os.path.join(treebunddir,RES_INDX)
|
treebundres = os.path.join(treebunddir,RES_INDX)
|
||||||
treebundtxt = "%s.txt" % (treebundres[0:-4])
|
treebundtxt = "%s.txt" % (treebundres[0:-4])
|
||||||
runcmd("iculslocs", "-i %s -N %s -T %s -b %s" % (outfile, dataname, tree, treebundtxt))
|
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("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)
|
return shutil.copy2(source_path, target_path)
|
||||||
|
|
||||||
def try_remove(options, path, dest):
|
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:
|
if not options.silent:
|
||||||
print('removing %s' % target_path)
|
print('removing %s' % target_path)
|
||||||
try_unlink(target_path)
|
try_unlink(target_path)
|
||||||
|
|
|
||||||
|
|
@ -817,7 +817,7 @@ def Execute(args, context, timeout=None, env=None, disable_core_files=False,
|
||||||
else:
|
else:
|
||||||
preexec_fn = setMaxVirtualMemory
|
preexec_fn = setMaxVirtualMemory
|
||||||
|
|
||||||
(process, exit_code, timed_out) = RunProcess(
|
(_process, exit_code, timed_out) = RunProcess(
|
||||||
context,
|
context,
|
||||||
timeout,
|
timeout,
|
||||||
args = args,
|
args = args,
|
||||||
|
|
@ -924,7 +924,7 @@ class LiteralTestSuite(TestSuite):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def ListTests(self, current_path, path, context, arch, mode):
|
def ListTests(self, current_path, path, context, arch, mode):
|
||||||
(name, rest) = CarCdr(path)
|
(name, _rest) = CarCdr(path)
|
||||||
result = [ ]
|
result = [ ]
|
||||||
for test in self.tests_repos:
|
for test in self.tests_repos:
|
||||||
test_name = test.GetName()
|
test_name = test.GetName()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user