8000 feat(lint): enforce cyclomatic complexity in python ruff config by VLukiantsev · Pull Request #1000 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

feat(lint): enforce cyclomatic complexity in python ruff config - #1000

Merged
VLukiantsev merged 3 commits into
mainfrom
feat/enforce-python-linter-complexity
Sep 28, 2026
Merged

VLukiantsev merged 3 commits into
mainfrom
feat/enforce-python-linter-complexity

Conversation

@VLukiantsev
@VLukiantsev VLukiantsev commented Sep 28, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Enforce Python cyclomatic complexity checks via Ruff (C901 / mccabe) with max-complexity = 15, paralleling Go's gocyclo enforcement. Refactor existing violating functions in tools/ into focused, single-responsibility helper routines to satisfy the complexity limit.

Motivation & Context

Python scripts under tools/ and throughout the repo have been growing in complexity without static lint guards to prevent sprawling conditional paths. Go already enforces both nested complexity (nestif: 4) and cyclomatic complexity (gocyclo: 15). Enabling Ruff's C901 rule with max-complexity = 15 introduces an equivalent guardrail in Python, preventing runaway complexity in scripts while keeping functions clean and maintainable.

Key Changes

  • Ruff Linter Configuration: Enabled C901 in [tool.ruff.lint.select] and configured [tool.ruff.lint.mccabe] max-complexity = 15 in pyproject.toml.
  • Refactored tools/benchmark/compare_trajectories.py: Decomposed parse_transcript into _parse_step_line and _record_tool_call helper routines.
  • Refactored tools/pr_review/review_pr_verify_posted.py: Decomposed verify_review_comments_posted into _is_initial_inline_posted, _is_re_review_thread_posted, _verify_all_checklist_items, and _mark_items_as_posted helpers, with explicit error handling on unknown re-review thread actions.
  • Unit Testing: Added test coverage in tools/pr_review/review_pr_verify_posted_test.py for unknown re-review thread action handling.

Assumptions

None — requirements and threshold were fully specified and confirmed.

Verification & Testing

  • Linter Checks:
    • ruff check . passed with 0 violations across the repository.
    • ruff format --check . passed cleanly.
  • Bazel Test Suite:
    • bazel test //tools/benchmark/... //tools/pr_review/... passed (16/16 test targets passed).
  • Pre-Commit Verification:
    • ./.githooks/pre-commit passed with all checks green (Ruff, Mypy, Buildifier, Go determinism).

Related Issues / Bugs

N/A

TAG=agy
CONV=22009166-566e-4d4f-ace4-c924d7d32241

0