diff --git a/emrun.py b/emrun.py index 16cc899bb7099..2cfc20c069f1f 100644 --- a/emrun.py +++ b/emrun.py @@ -1596,7 +1596,7 @@ def parse_args(args): return parser.parse_args(args) -def run(args): # noqa: C901, PLR0912, PLR0915 +def run(args): # ruff: ignore[complex-structure, too-many-branches, too-many-statements] """Future modifications should consider refactoring to reduce complexity. * The McCabe cyclomatiic complexity is currently 74 vs 10 recommended. diff --git a/pyproject.toml b/pyproject.toml index ddd9da9a87c97..992f2ce9a5707 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,59 +39,59 @@ lint.select = [ ] lint.external = [ "D" ] lint.ignore = [ - "D100", # https://docs.astral.sh/ruff/rules/undocumented-public-module/ - "D101", # https://docs.astral.sh/ruff/rules/undocumented-public-class/ - "D102", # https://docs.astral.sh/ruff/rules/undocumented-public-method/ - "D103", # https://docs.astral.sh/ruff/rules/undocumented-public-function/ - "D104", # https://docs.astral.sh/ruff/rules/undocumented-public-package/ - "D105", # https://docs.astral.sh/ruff/rules/undocumented-magic-method/ - "D106", # https://docs.astral.sh/ruff/rules/undocumented-public-nested-class/ - "D107", # https://docs.astral.sh/ruff/rules/undocumented-public-init/ - "D203", # https://docs.astral.sh/ruff/rules/incorrect-blank-line-before-class/ - "D213", # https://docs.astral.sh/ruff/rules/multi-line-summary-second-line/ - "D401", # https://docs.astral.sh/ruff/rules/non-imperative-mood/ - "B011", # See https://github.com/PyCQA/flake8-bugbear/issues/66 - "B023", - "B026", - "E272", - "E402", - "E241", - "E266", - "E501", - "E721", - "E741", - "E111", # Does not seem to honor `indent-width = 2` above - "E114", # Does not seem to honor `indent-width = 2` above - "E261", - "PERF203", - "PERF401", - "PLC0415", - "PLR0904", - "PLR0916", - "PLR0914", - "PLR1702", - "PLR1704", - "PLR5501", - "PLR6301", - "PLW0602", - "PLW0603", - "PLW0717", # https://docs.astral.sh/ruff/rules/too-many-statements-in-try-clause - "PLW1510", - "PLW2901", - "RUF012", # https://docs.astral.sh/ruff/rules/mutable-class-default/ - "RUF015", # https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element/ - "RUF027", # https://docs.astral.sh/ruff/rules/missing-f-string-syntax/ - "RUF039", # https://docs.astral.sh/ruff/rules/unraw-re-pattern/ - "RUF067", # https://docs.astral.sh/ruff/rules/non-empty-init-module/ - "UP030", # TODO - "UP031", # TODO - "UP032", # TODO + "undocumented-public-module", + "undocumented-public-class", + "undocumented-public-method", + "undocumented-public-function", + "undocumented-public-package", + "undocumented-magic-method", + "undocumented-public-nested-class", + "undocumented-public-init", + "incorrect-blank-line-before-class", + "multi-line-summary-second-line", + "non-imperative-mood", + "assert-false", # See https://github.com/PyCQA/flake8-bugbear/issues/66 + "function-uses-loop-variable", + "star-arg-unpacking-after-keyword-arg", + "multiple-spaces-before-keyword", + "module-import-not-at-top-of-file", + "multiple-spaces-after-comma", + "multiple-leading-hashes-for-block-comment", + "line-too-long", + "type-comparison", + "ambiguous-variable-name", + "indentation-with-invalid-multiple", # Does not seem to honor `indent-width = 2` above + "indentation-with-invalid-multiple-comment", # Does not seem to honor `indent-width = 2` above + "too-few-spaces-before-inline-comment", + "try-except-in-loop", + "manual-list-comprehension", + "import-outside-top-level", + "too-many-public-methods", + "too-many-boolean-expressions", + "too-many-locals", + "too-many-nested-blocks", + "redefined-argument-from-local", + "collapsible-else-if", + "no-self-use", + "global-variable-not-assigned", + "global-statement", + "too-many-statements-in-try-clause", + "subprocess-run-without-check", + "redefined-loop-name", + "mutable-class-default", + "unnecessary-iterable-allocation-for-first-element", + "missing-f-string-syntax", + "unraw-re-pattern", + "non-empty-init-module", + "format-literals", # TODO + "printf-string-formatting", # TODO + "f-string", # TODO ] -lint.per-file-ignores."tools/ports/*.py" = [ "ARG001", "ARG005" ] -lint.per-file-ignores."test/other/ports/*.py" = [ "ARG001" ] -lint.per-file-ignores."test/parallel_testsuite.py" = [ "ARG002" ] -lint.per-file-ignores."test/test_benchmark.py" = [ "ARG002" ] -lint.per-file-ignores."test/*.py" = [ "RUF005" ] +lint.per-file-ignores."tools/ports/*.py" = [ "unused-function-argument", "unused-lambda-argument" ] +lint.per-file-ignores."test/other/ports/*.py" = [ "unused-function-argument" ] +lint.per-file-ignores."test/parallel_testsuite.py" = [ "unused-method-argument" ] +lint.per-file-ignores."test/test_benchmark.py" = [ "unused-method-argument" ] +lint.per-file-ignores."test/*.py" = [ "collection-literal-concatenation" ] lint.mccabe.max-complexity = 51 # Recommended: 10 lint.pylint.allow-magic-value-types = [ "bytes", diff --git a/requirements-dev.txt b/requirements-dev.txt index ffdb62469338d..84c746d35969d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,7 +7,7 @@ coverage[toml]==7.15.0 mypy==2.3.0 psutil==7.0.0 -ruff==0.15.21 +ruff==0.16.0 types-requests==2.32.0.20241016 unittest-xml-reporting==3.2.0 deadcode==2.3.1 diff --git a/test/common.py b/test/common.py index 0523d386a93b5..7a341aca42e0e 100644 --- a/test/common.py +++ b/test/common.py @@ -912,7 +912,7 @@ def is_ldflag(f): for i, arg in enumerate(args): if arg in {'--pre-js', '--post-js'}: args[i] = None - args[i + 1] = None # noqa: B909 + args[i + 1] = None # ruff: ignore[loop-iterator-mutation] args = [arg for arg in args if arg is not None] return args @@ -1199,7 +1199,7 @@ def get_build_dir(self): ensure_dir(ret) return ret - def get_library(self, name, generated_libs, configure=['sh', './configure'], # noqa + def get_library(self, name, generated_libs, configure=['sh', './configure'], # ruff: ignore[mutable-argument-default] configure_args=None, make=None, make_args=None, env_init=None, cache_name_extra='', native=False, force_rebuild=False): @@ -1288,7 +1288,7 @@ def run_process(self, cmd, check=True, **kwargs): rtn.stderr = None return rtn - def emcc(self, filename, args=[], **kwargs): # noqa + def emcc(self, filename, args=[], **kwargs): # ruff: ignore[mutable-argument-default] filename = maybe_test_file(filename) compile_only = '-c' in args or '-sSIDE_MODULE' in args cmd = [compiler_for(filename), filename] + self.get_cflags(compile_only=compile_only) + args diff --git a/test/sockets/socket_relay.py b/test/sockets/socket_relay.py index 77db9eb37ab03..1796f422ebdc5 100644 --- a/test/sockets/socket_relay.py +++ b/test/sockets/socket_relay.py @@ -23,7 +23,7 @@ class Listener(threading.Thread): - other: Listener | None = None # noqa: F821 + other: Listener | None = None # ruff: ignore[undefined-name] def run(self): self.conn = None diff --git a/test/test_benchmark.py b/test/test_benchmark.py index b1ce974922927..c0afa54568c25 100644 --- a/test/test_benchmark.py +++ b/test/test_benchmark.py @@ -1188,7 +1188,7 @@ def test_zzz_poppler(self): } ''' % DEFAULT_ARG) - def lib_builder(name, native, env_init): # noqa + def lib_builder(name, native, env_init): # ruff: ignore[unused-function-argument] if '-m64' in env_init.get('CFLAGS', ''): env_init['CPPFLAGS'] = '-m64' env_init['LDFLAGS'] = '-m64' diff --git a/test/test_closure_args_port.py b/test/test_closure_args_port.py index 07f6463667a58..a3fc9f9c1e460 100644 --- a/test/test_closure_args_port.py +++ b/test/test_closure_args_port.py @@ -1,7 +1,7 @@ import os -def get(ports, settings, shared): # noqa: ARG001 +def get(ports, settings, shared): # ruff: ignore[unused-function-argument] return [] @@ -9,7 +9,7 @@ def clear(ports, settings, shared): pass -def linker_setup(ports, settings): # noqa: ARG001 +def linker_setup(ports, settings): # ruff: ignore[unused-function-argument] externs_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_closure_externs.js') settings.CLOSURE_ARGS += [f'--externs={externs_file}'] diff --git a/test/test_codesize.py b/test/test_codesize.py index 15ef6e106c881..b89b585526755 100644 --- a/test/test_codesize.py +++ b/test/test_codesize.py @@ -404,7 +404,7 @@ def test_codesize_cxx(self, args): # prune unused imports/exports from it. See #27217. 'esm_integration': (['-O3', '-sWASM_ESM_INTEGRATION', '-Wno-experimental'],), }) - def test_codesize_hello(self, args, kwargs={}): # noqa + def test_codesize_hello(self, args, kwargs={}): # ruff: ignore[mutable-argument-default] self.run_codesize_test('hello_world.c', args, **kwargs) @parameterized({ diff --git a/test/test_core.py b/test/test_core.py index 4e55825335dee..f008b667cea92 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -9954,7 +9954,7 @@ def test_fcoverage_mapping(self): self.assertEqual(expected, self.run_process([LLVM_COV, 'show', 'test_hello_world.wasm', '-instr-profile=out.profdata'], stdout=PIPE).stdout) # Generate tests for everything -def make_run(name, cflags=None, settings=None, env=None, # noqa +def make_run(name, cflags=None, settings=None, env=None, # ruff: ignore[blank-lines-top-level] v8_args=None, node_args=None, require_wasm64=False, init=None): @@ -9969,7 +9969,7 @@ def make_run(name, cflags=None, settings=None, env=None, # noqa # we need to pass this flag here to avoid warnings from compile-only commands. cflags.append('-Wno-unused-command-line-argument') - TT = type(name, (TestCoreBase,), dict(run_name=name, env=env, __module__=__name__)) # noqa + TT = type(name, (TestCoreBase,), dict(run_name=name, env=env, __module__=__name__)) # ruff: ignore[unnecessary-collection-call, undefined-name] def tearDown(self): try: diff --git a/test/test_other.py b/test/test_other.py index 09df84c0ed5c5..6a8019e302735 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -901,11 +901,11 @@ def test_cmake(self, test_dir, output_file, cmake_args): generators = ['Unix Makefiles', 'Ninja', 'Eclipse CDT4 - Ninja'] configurations = { - 'MinGW Makefiles' : {'build' : ['mingw32-make'] }, # noqa - 'NMake Makefiles' : {'build' : ['nmake', '/NOLOGO']}, # noqa - 'Unix Makefiles' : {'build' : ['make']}, # noqa - 'Ninja' : {'build' : ['ninja']}, # noqa - 'Eclipse CDT4 - Ninja': {'build' : ['ninja']}, # noqa + 'MinGW Makefiles' : {'build' : ['mingw32-make'] }, # ruff: ignore[whitespace-before-close-bracket, whitespace-before-punctuation] + 'NMake Makefiles' : {'build' : ['nmake', '/NOLOGO']}, # ruff: ignore[whitespace-before-punctuation] + 'Unix Makefiles' : {'build' : ['make']}, # ruff: ignore[whitespace-before-punctuation] + 'Ninja' : {'build' : ['ninja']}, # ruff: ignore[whitespace-before-punctuation] + 'Eclipse CDT4 - Ninja': {'build' : ['ninja']}, # ruff: ignore[whitespace-before-punctuation] } for generator in generators: conf = configurations[generator] @@ -7949,15 +7949,15 @@ def test(p1, p2, p3, last, expected): return os.path.getsize('a.out.wasm') print('no bad ctor') - first = test(1000, 2000, 3000, 0xe, 0x58e) # noqa: E221 + first = test(1000, 2000, 3000, 0xe, 0x58e) # ruff: ignore[multiple-spaces-before-operator] second = test(3000, 1000, 2000, 0xe, 0x8e5) - third = test(2000, 3000, 1000, 0xe, 0xe58) # noqa: E221 + third = test(2000, 3000, 1000, 0xe, 0xe58) # ruff: ignore[multiple-spaces-before-operator] print(first, second, third) assert first == second and second == third print('with bad ctor') - first = test(1000, 2000, 3000, 0xf, 0x58f) # noqa: E221, 2 will succeed + first = test(1000, 2000, 3000, 0xf, 0x58f) # ruff: ignore[multiple-spaces-before-operator], 2 will succeed second = test(3000, 1000, 2000, 0xf, 0x8f5) # 1 will succeed - third = test(2000, 3000, 1000, 0xf, 0xf58) # noqa: E221, 0 will succeed + third = test(2000, 3000, 1000, 0xf, 0xf58) # ruff: ignore[multiple-spaces-before-operator], 0 will succeed print(first, second, third) self.assertLess(first, second) self.assertLess(second, third) @@ -8224,7 +8224,7 @@ def test(contents): self.assertNotContained(error, read_file('a.out.js')) def test_warn_module_out_err(self): - def test(contents, expected, args=[], assert_returncode=0): # noqa + def test(contents, expected, args=[], assert_returncode=0): # ruff: ignore[mutable-argument-default] create_file('src.c', r''' #include int main() { diff --git a/test/test_posixtest.py b/test/test_posixtest.py index acb44d4e523e6..0cc98a2532db5 100644 --- a/test/test_posixtest.py +++ b/test/test_posixtest.py @@ -28,8 +28,6 @@ class posixtest(RunnerCore): This class get populated dynamically below. """ - pass # noqa: PIE790 - def filter_tests(all_tests): prefixes = ( diff --git a/tools/building.py b/tools/building.py index ffc77781f965b..bf635e96142f3 100644 --- a/tools/building.py +++ b/tools/building.py @@ -1289,7 +1289,7 @@ def run_binaryen_command(tool, infile, outfile=None, args=None, debug=False, std return ret -def run_wasm_opt(infile, outfile=None, args=[], **kwargs): # noqa +def run_wasm_opt(infile, outfile=None, args=[], **kwargs): # ruff: ignore[mutable-argument-default] return run_binaryen_command('wasm-opt', infile, outfile, args=args, **kwargs) diff --git a/tools/cmdline.py b/tools/cmdline.py index 2fada9061e245..52c8e0271006f 100644 --- a/tools/cmdline.py +++ b/tools/cmdline.py @@ -195,7 +195,7 @@ def parse_s_args(): user_settings[key] = value -def parse_args(newargs): # noqa: C901, PLR0912, PLR0915 +def parse_args(newargs): # ruff: ignore[complex-structure, too-many-branches, too-many-statements] """Future modifications should consider refactoring to reduce complexity. * The McCabe cyclomatiic complexity is currently 117 vs 10 recommended. diff --git a/tools/extract_metadata.py b/tools/extract_metadata.py index f9a11ada06ed7..e8966b8000b3a 100644 --- a/tools/extract_metadata.py +++ b/tools/extract_metadata.py @@ -3,7 +3,7 @@ # University of Illinois/NCSA Open Source License. Both these licenses can be # found in the LICENSE file. -# ruff:noqa: F841 +# ruff: file-ignore[unused-variable] import logging from dataclasses import dataclass diff --git a/tools/file_packager.py b/tools/file_packager.py index 26713f07c80a3..5db149ef22de7 100755 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -347,7 +347,7 @@ def generate_object_file(data_files): shared.check_call(cmd) -def main(): # noqa: C901, PLR0912, PLR0915 +def main(): # ruff: ignore[complex-structure, too-many-branches, too-many-statements] """Future modifications should consider refactoring to reduce complexity. * The McCabe cyclomatiic complexity is currently 60 vs 10 recommended. diff --git a/tools/link.py b/tools/link.py index c287e1311c2e6..527996f7672d5 100644 --- a/tools/link.py +++ b/tools/link.py @@ -842,7 +842,7 @@ def add_required_heap_symbols(): @ToolchainProfiler.profile_block('linker_setup') -def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915 +def phase_linker_setup(options, linker_args): # ruff: ignore[complex-structure, too-many-branches, too-many-statements] """Future modifications should consider refactoring to reduce complexity. * The McCabe cyclomatiic complexity is currently 244 vs 10 recommended. diff --git a/tools/ports/__init__.py b/tools/ports/__init__.py index 60cb8d791e41c..40033bdb9b35a 100644 --- a/tools/ports/__init__.py +++ b/tools/ports/__init__.py @@ -223,7 +223,7 @@ def install_headers(src_dir, pattern='*.h', target=None): maybe_copy(f, os.path.join(dest, os.path.basename(f))) @staticmethod - def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=[], exclude_files=[], exclude_dirs=[], srcs=[]): # noqa + def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=[], exclude_files=[], exclude_dirs=[], srcs=[]): # ruff: ignore[mutable-argument-default] mangled_name = str(Path(output_path).relative_to(Path(cache.get_sysroot(True)) / 'lib')) mangled_name = mangled_name.replace(os.sep, '_').replace('.a', '').replace('-emscripten', '') build_dir = os.path.join(Ports.get_build_dir(), port_name, mangled_name) diff --git a/tools/response_file.py b/tools/response_file.py index b33a407723df8..92fee70ca4cb8 100644 --- a/tools/response_file.py +++ b/tools/response_file.py @@ -99,7 +99,7 @@ def expand_response_file(arg): if DEBUG: logging.warning(f'failed to parse response file {response_filename} with guessed encoding "{guessed_encoding}". Trying default system encoding...') # If that fails, try with the Python default locale.getpreferredencoding() - with open(response_filename) as f: # noqa: PLW1514 + with open(response_filename, encoding=None) as f: args = f.read() args = shlex.split(args) diff --git a/tools/settings.py b/tools/settings.py index 06fb37d704df7..167d616be5321 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -344,11 +344,11 @@ def infer_types(self): def dict(self): return self.attrs - def external_dict(self, skip_keys={}): # noqa + def external_dict(self, skip_keys={}): # ruff: ignore[mutable-argument-default] external_settings = {} for key, value in self.dict().items(): if value != self.defaults.get(key) and key not in INTERNAL_SETTINGS and key not in skip_keys: - external_settings[key] = value # noqa: PERF403 + external_settings[key] = value # ruff: ignore[manual-dict-comprehension] if not self.attrs['STRICT']: # When not running in strict mode we also externalize all legacy settings # (Since the external tools do process LEGACY_SETTINGS themselves) @@ -419,9 +419,9 @@ def check_type(self, name, value): return # Allow integers 1 and 0 for type `bool` if expected_type == bool: - if value in (1, 0): # noqa: PLR6201 + if value in {1, 0}: value = bool(value) - if value in ('True', 'False', 'true', 'false'): # noqa: PLR6201 + if value in {'True', 'False', 'true', 'false'}: exit_with_error(f'attempt to set `{name}` to `{value}`; use 1/0 to set boolean settings') if type(value) is not expected_type: exit_with_error(f'setting `{name}` expects `{expected_type.__name__}` but got `{type(value).__name__}`') diff --git a/tools/shared.py b/tools/shared.py index 7be1ad461f051..ffb53996376a0 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -201,7 +201,7 @@ def exec_process(cmd): utils.exec(cmd) -def run_js_tool(filename, jsargs=[], node_args=[], **kw): # noqa: B006 +def run_js_tool(filename, jsargs=[], node_args=[], **kw): # ruff: ignore[mutable-argument-default] """Execute a javascript tool. This is used by emcc to run parts of the build process that are diff --git a/tools/system_libs.py b/tools/system_libs.py index 57f0b3e5ed412..90f0e965cc6f9 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -3,7 +3,7 @@ # University of Illinois/NCSA Open Source License. Both these licenses can be # found in the LICENSE file. -# ruff: noqa: RUF005 +# ruff: file-ignore[collection-literal-concatenation] import itertools import logging @@ -51,7 +51,7 @@ def files_in_path(path: str, filenames: list[str]): return [os.path.join(srcdir, f) for f in filenames] -def glob_in_path(path: str, glob_pattern: str, excludes: set[str] = set()): # noqa: B006 +def glob_in_path(path: str, glob_pattern: str, excludes: set[str] = set()): # ruff: ignore[mutable-argument-default] srcdir = utils.path_from_root(path) files = iglob(os.path.join(srcdir, glob_pattern), recursive=True) return sorted(f for f in files if os.path.basename(f) not in excludes) diff --git a/tools/webidl_binder.py b/tools/webidl_binder.py index 0f37dd4034bf9..56085c55a9ee5 100644 --- a/tools/webidl_binder.py +++ b/tools/webidl_binder.py @@ -395,7 +395,7 @@ def type_to_cdec(raw): return ret + '*' -def render_function(class_name, func_name, sigs, return_type, non_pointer, # noqa: C901, PLR0912, PLR0915 +def render_function(class_name, func_name, sigs, return_type, non_pointer, # ruff: ignore[complex-structure, too-many-branches, too-many-statements] copy, operator, constructor, is_static, func_scope, call_content=None, const=False, array_attribute=False, bind_to=None):