Repository navigation
ci(test): OPS-9049 replace flake8 with ruff and upgrade the ruff hook to 0.17.3 - #17536
Conversation
The flake8 hook passed its arguments as a YAML flow list. YAML splits a flow list at every comma, so flake8 received --select=C alone, with E, F, W, B, B950, and E501 as loose arguments. With no --max-complexity, it reported nothing. It passed a planted syntax error and a planted unused import, and it took 17 to 27 s of each CI pre-commit run. The ruff hook already reports both of those problems. Remove the flake8 hook, and update the guideline, test docstring, and generator comment that mention it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Dmitry Tokarev <dtokarev@nvidia.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Remove Flake8 references .pre-commit-config.yaml, .ai/python-guidelines.md, docs/fern/scripts/tests/test_gen_python_api.py, lib/bindings/python/codegen/src/gen_python_prometheus_names.rs |
The pre-commit configuration removes the Flake8 hook. The guidelines and code comments remove or replace Flake8 references with Ruff. |
Priority:
Estimated code review effort: 1 (Trivial) | ~5 minutes
Merge Risk: 
Minimal · up to 8bcb6
-
The PR removes the Flake8 hook and updates its documentation references without an identified merge-blocking issue.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)
Full details: Description check
-
Explanation
The pull request description includes all required sections: Overview, Key Changes, Validation, Issues and Ongoing Work, issue closure, and the checklist. It provides detailed technical context and validation results. The checklist item remains unchecked, but this is non-critical for the description check.
Full details: Title check
-
Explanation
The title names the two changes the PR makes: replacing flake8 with ruff in the pre-commit setup, and upgrading the ruff hook to 0.17.3. The changeset removes the flake8 pre-commit hook and updates references to flake8 to name ruff or omit it, which matches the first part of the title. The changeset summaries do not mention the ruff version upgrade to 0.17.3, so that part of the title is not visible in the provided file summaries. The title's main point is the flake8-to-ruff replacement, so it is related to the main change.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
The hook pinned ruff-pre-commit v0.5.2. Move it to v0.17.3, and to the hook id ruff-check, because ruff is now the only Python linter. In v0.17.3 the old id ruff is a legacy alias. Under the repository configuration, ruff 0.17.3 enables 407 rules by default, against 60 for 0.5.2. With them it reports 9,238 findings on main. Pin select to E4, E7, E9, and F, the old default set, so that enforcement does not change. The only rule that drops out is E999, because newer ruff always reports syntax errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Dmitry Tokarev <dtokarev@nvidia.com>
W605 flags invalid escape sequences. PLW0602 flags a global name that a function never assigns, which is ruff's version of pyflakes F824. Ruff has no F824. Neither rule has findings on main. Add a TODO to enable flake8-bugbear (B) after its findings on main are fixed. Ruff has no B950, and E501 is the closest ruff rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Dmitry Tokarev <dtokarev@nvidia.com>
Three files skip linting with "# flake8: noqa". Ruff honors that directive too, but flake8 no longer runs, so the name points to a removed tool. Rename the three directives to "# ruff: noqa", which ruff treats the same way. Without a directive, ruff reports 4 E402 in kvbm/__init__.py and 5 F401 in dynamo/llm/__init__.py, so two of the directives still do work. exceptions.py has no findings either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Dmitry Tokarev <dtokarev@nvidia.com>
The file-level "# ruff: noqa" in exceptions.py suppressed nothing: ruff reports no findings for the file without it. Remove it, so that ruff checks the file like any other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Dmitry Tokarev <dtokarev@nvidia.com>
Remove the file-level "# ruff: noqa" from dynamo/llm/__init__.py, and fix the 5 F401 findings that it hid. Four of them are public re-exports (EngineType, make_engine, run_input, HttpError) that other modules import from dynamo.llm. Write them as "X as X", like the other re-exports in the file. The fifth, "import logging", is unused, so remove it. The module binds the same names as before, except logging. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Dmitry Tokarev <dtokarev@nvidia.com>
✅ Dynamo PR CI passed — run 40767121576 (attempt 1) on
|
Linear: OPS-9049
Overview
The flake8 hook takes 17 to 27 s of each CI pre-commit run, but it enforces nothing. YAML splits its
argslist at every comma, so flake8 receives only--select=C. This PR removes the hook. Ruff is then the only Python linter, so this PR also moves the ruff hook from 0.5.2 to 0.17.3. It pins the old rule set, so nothing that passed before fails now, and it adds two rules that have no findings on main.Key Changes
Core logic: none. The change is configuration only.
.pre-commit-config.yaml: the flake8 hook is gone.ruff-pre-commitmoves fromv0.5.2tov0.17.3, and the hook id fromrufftoruff-check. Inv0.17.3,ruffis a legacy alias.pyproject.toml:[tool.ruff.lint] select = ["E4", "E7", "E9", "F", "W605", "PLW0602"]. The first four are the default rule set of ruff 0.5.2.W605flags invalid escape sequences, andPLW0602flags aglobalname that is never assigned. A TODO records the next step: enable flake8-bugbear (B) after its findings on main are fixed..ai/python-guidelines.md, a docstring indocs/fern/scripts/tests/test_gen_python_api.py, and a comment inlib/bindings/python/codegen/src/gen_python_prometheus_names.rsmentioned flake8. They now name ruff or drop the mention.lib/bindings/kvbm/python/kvbm/__init__.py: the file-level# flake8: noqabecomes# ruff: noqa, which ruff treats the same way. The kvbm package is deprecated, so this PR does not clean it up.lib/bindings/python/src/dynamo/llm/exceptions.py: the file-level directive is removed, because it suppressed nothing. Ruff now checks that file.lib/bindings/python/src/dynamo/llm/__init__.py: the file-level directive is removed, and the 5F401findings it hid are fixed. Four are public re-exports (EngineType,make_engine,run_input,HttpError), now written asX as Xlike the other re-exports in the file. The fifth,import logging, was unused and is gone.Validation
flake8 enforced nothing
The
argsline was[--max-line-length=88, --select=C,E,F,W,B,B950, --extend-ignore = E203,E501]. PyYAML, which pre-commit uses, parses it into--select=C,E,F,W,B,B950,--extend-ignore = E203, andE501. With onlyCselected and no--max-complexity, flake8 has nothing to report. The line has not changed sincedf90e29eba.pre-commit run flake8on a planted unused import and a planted syntax errorPassedpre-commit run ruffon the same two filesFailed: it reports the syntax error and fixes the unused import.pyfiles of maina5c73615d0E999andF401Fixing the arguments instead is not a real option. The intended rules flag about 3,250 lines on main, and 2,758 of them are
W503, which conflicts with black. In the rule families that ruff also covers (F,E4,E7,E9), they flag 149 more lines than ruff. All 149 follow conventions that ruff accepts on purpose. Of the 123 late imports, 110 followpytest.importorskipand 13 follow other allowed setup code. The other 26 are 12import X as Xre-exports, 7 unused names that start with_, 6 duplicate imports, and 1 import inside a loop.The ruff upgrade does not change enforcement
UP045, 1,313UP006, 699I001, 569BLE001, and more)selectThe only rule that drops out is
E999. Newer ruff removed it as a rule, because it always reports syntax errors. No nestedpyproject.tomlhas a[tool.ruff]table, so the root pin applies to the whole repository.The upgraded hook, run through pre-commit:
E501.E402.These results also keep the two rewritten sentences true.
pre-commit run --all-filespasses locally with 40 hooks.Two added rules and a TODO
These two rules close the gaps between the intended flake8 rules and ruff that cost nothing today:
W605W605, an invalid escape sequence such as"\d+"r"\d+"passesPLW0602F824, which ruff does not have: aglobalname that the function never assignsglobalpassesThe TODO is for flake8-bugbear (
B), which never ran here because the hook never installed the plugin. On main,ruff check --select Breports 254 findings, among them 23B023(a closure that captures a loop variable). Those need their own PR. Ruff has noB950, so the TODO namesE501(line too long) as the closest ruff rule.The file-level noqa directives
Ruff skips a file that has either
# flake8: noqaor# ruff: noqa. Without a directive, ruff reports 4E402in the kvbm__init__.py, 5F401indynamo/llm/__init__.py, and nothing inexceptions.py.__init__.pykeeps a whole-file# ruff: noqa, because the package is deprecated.exceptions.pyloses its directive, and the ruff, black, and isort hooks pass on it.dynamo/llm/__init__.pyloses its directive, and ruff 0.17.3 reports no findings after the fixes. The four re-exports have users: for example,components/src/dynamo/mocker/main.pyimportsEngineType,make_engine, andrun_inputfromdynamo.llm, andcomponents/src/dynamo/common/utils/guided_json.pyimportsHttpError. Nothing in the repository usesdynamo.llm.logging. An AST comparison shows that the module binds the same 61 names as before, withoutlogging.A local import of
dynamo.llmwas not possible: the compileddynamo._coreon hand predates main'sAisPerfConfig, and the original file fails the same way there. The CI test jobs builddynamo._corefrom this PR and import these names.CI
This PR edits
.pre-commit-config.yaml, so its ownpre-commitjob starts with an empty hook cache. Such cold runs took 152 to 189 s on 2026-10-28, which is close to the 3-minute step limit that #17532 raises. The cold job 123074777938 of the first commit passed with a 122 s step, and flake8 does not appear in its log. Part of that gap comes from a faster runner:blacktook 34 s there, against 47 to 55 s in the other runs. The cold job 123083739885 of the second commit passed with a 107 s step, and itsruff checkhook ran ruff 0.17.3 and passed.Issues and Ongoing Work
Pull Request Checklist
/pr-checklistskill.🤖 Generated with Claude Code