From 9b3ad51d06a82afa4f210634a8cb56b20cdddf30 Mon Sep 17 00:00:00 2001 From: Teemu Kuusisto Date: Tue, 17 Nov 2026 13:14:10 +0000 Subject: [PATCH] chore(lint): enable ARG, BLE, SLF and PL ruff rules Turn on four more Ruff rule families for every Python file in the repository: flake8-unused-arguments (ARG), flake8-blind-except (BLE), flake8-self (SLF) and the Pylint set (PL). SLF and the Pylint error rules report nothing. ARG needed two fixes: - `setup(app)` in the Sphinx config is removed. Sphinx calls the config's `setup` and discards what it returns, and the parallel-safe flags it returned only count for registered extensions, so it did nothing; a config without `setup` is skipped. - A dead `temp_state_root` parameter is dropped from `run_live_acceptance` in the local-assistant GPU test along with its argument at the single call site. What still fires is waived in ruff.toml. The global ignores give their reason, and each per-file entry states the rule new code under it has to keep: - PLR0912, PLR0913 and PLR0915 are ignored for every file, since acting on them means restructuring existing scripts. PLR2004 is ignored for every file as well: it flags inline numeric literals in comparisons, and naming them is a separate cleanup. - BLE001 is allowed in comfyui_therock_gpu_test.py, therock_sdk_install_test.py and vllm_therock_gpu_test.py. - PLC0415 and PLW0603 are allowed in vllm_route_check.py, whose self-test imports inside the function and rebinds a module global it restores in a `finally`. - ARG001, PLW0603 and PLW1510 are allowed in the rocm-doctor eval hooks and their tests; ARG001 covers only the unused parameters of setup() and teardown(). Those files are waived rather than edited because a change to skills/rocm-doctor/ on main opens a bump pull request in the federated copy. A waived rule checks nothing anywhere in that file, so new code in those files is reviewed by hand. ruff.toml and .pre-commit-config.yaml also described the Python scope as covering "engine workers", which is Rust-only; both now say every Python file in the repository, so they stay true as Python files are added. Signed-off-by: Teemu Kuusisto --- .pre-commit-config.yaml | 2 +- docs/rocm-docs/conf.py | 7 ---- ruff.toml | 39 ++++++++++++++++++++- scripts/local_assistant_therock_gpu_test.py | 3 +- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43120b797d..007d1df18d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,7 +43,7 @@ repos: args: [--fix=lf] # repo standardises on LF endings (see .gitattributes) exclude: '^THIRD_PARTY_NOTICES\.txt$' - # Python: lint + format the helper scripts and engine workers. + # Python: lint + format every Python file in the repository. - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.17.3 hooks: diff --git a/docs/rocm-docs/conf.py b/docs/rocm-docs/conf.py index 72cc906ee4..886df0aae2 100644 --- a/docs/rocm-docs/conf.py +++ b/docs/rocm-docs/conf.py @@ -76,10 +76,3 @@ def filter(self, record: logging.LogRecord) -> bool: "sphinx_design", ] exclude_patterns = [] - -# -- Sphinx setup ---------------------------------------------------------- - - -def setup(app): - """Sphinx setup""" - return {"parallel_read_safe": True, "parallel_write_safe": True} diff --git a/ruff.toml b/ruff.toml index 55c3eda733..8af4ab98bc 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,4 +1,4 @@ -# Ruff configuration for the Python helper scripts (scripts/) and engine workers. +# Ruff configuration for every Python file in the repository. # Formatting uses Ruff's defaults (88-column, double quotes), which the # `ruff-format` pre-commit hook enforces. @@ -15,7 +15,44 @@ select = [ "SIM", # flake8-simplify "C4", # flake8-comprehensions "RUF", # Ruff-specific rules + "ARG", # flake8-unused-arguments + "BLE", # flake8-blind-except + "SLF", # flake8-self (private-member access) + "PL", # Pylint (PLC/PLE/PLR/PLW) ] ignore = [ "E501", # line length is enforced by the formatter; long comments/URLs are fine + # + # Pylint refactor metrics, ignored for every file: acting on them means + # restructuring existing scripts, which enabling the rule families does not do. + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + # + # Not a refactor metric: it flags inline numeric literals in comparisons, and + # replacing them with named constants is a separate cleanup. + "PLR2004", # magic-value-comparison ] + +[lint.per-file-ignores] +# A waived rule checks nothing anywhere in that file, so new code in these files +# is reviewed by hand against the rule stated on the entry. +# +# A blind `except` must report the failure, fall back, or keep the error for a +# later message. +"scripts/comfyui_therock_gpu_test.py" = ["BLE001"] # blind-except +"scripts/therock_sdk_install_test.py" = ["BLE001"] # blind-except +"scripts/vllm_therock_gpu_test.py" = ["BLE001"] # blind-except +# Function-level imports belong to the self-test only; a module global rebound +# here is restored in a `finally`. +"scripts/vllm_route_check.py" = ["PLC0415", "PLW0603"] # import-outside-top-level + global-statement +# The skills/rocm-doctor/ entries stay waived rather than edited: a change there on +# main opens a "Bump rocm-doctor" pull request in amd/skills through its nightly +# workflow (see the `skills/rocm-doctor/` part of AGENTS.md). +# +# ARG001 covers only the unused `workspace` and `case` parameters of setup() and +# teardown(); any other unused argument in the file is removed. `_active` is the +# only module global the hooks rebind. +"skills/rocm-doctor/evals/hooks.py" = ["ARG001", "PLW0603"] # unused-function-argument + global-statement +# A `subprocess.run` here has its returncode asserted by the test. +"skills/rocm-doctor/evals/test_hooks.py" = ["PLW1510"] # subprocess-run-without-check diff --git a/scripts/local_assistant_therock_gpu_test.py b/scripts/local_assistant_therock_gpu_test.py index 47769721f9..bf1728d9ff 100644 --- a/scripts/local_assistant_therock_gpu_test.py +++ b/scripts/local_assistant_therock_gpu_test.py @@ -68,7 +68,7 @@ def main() -> int: print_step(f"Copied ROCm runtime registry from {source_state}.") localize_huggingface_cache(env, repo_root) - return run_live_acceptance(args, rocm, env, temp_state_root) + return run_live_acceptance(args, rocm, env) finally: if temp_state_root is not None and not args.keep_state: print_step(f"Removing temporary ROCm CLI state under {temp_state_root}.") @@ -79,7 +79,6 @@ def run_live_acceptance( args: argparse.Namespace, rocm: Path, env: dict[str, str], - temp_state_root: Path | None, ) -> int: data_dir = rocm_cli_data_dir(env) service_id = args.service_id