Skip to content

Replace pylint + autopep8 with ruff#1300

Draft
sbryngelson wants to merge 4 commits intoMFlowCode:masterfrom
sbryngelson:ruff
Draft

Replace pylint + autopep8 with ruff#1300
sbryngelson wants to merge 4 commits intoMFlowCode:masterfrom
sbryngelson:ruff

Conversation

@sbryngelson
Copy link
Member

Summary

Resolves #1281 — replaces pylint + autopep8 with ruff for all Python linting and formatting. Ruff is ~200-500x faster (under 0.2s vs 30-90s for the old pylint + autopep8 pipeline across 226 Python files).

What changed

  • Formatting: autopep8 → ruff format. Per-file find | xargs replaced with direct directory-level ruff format calls.
  • Linting: 3 separate pylint invocations → ruff check with rule sets E (pycodestyle), F (pyflakes), W (warnings), I (isort), PL (pylint-equivalent).
  • Auto-fix: ruff check --fix runs automatically in both ./mfc.sh format and ./mfc.sh lint to fix safe issues (import sorting, unused f-prefixes, etc.) before checking.
  • Config: New ruff.toml at repo root (centralized, replaces scattered pylint/autopep8 config). Only 6 rules ignored — all high-count structural/style rules (too-many-branches, magic-value-comparison, etc.).
  • Inline comments: Removed all ~229 # pylint: disable= comments. Added ~12 targeted # noqa: comments for intentional global statements.
  • Code fixes (not just suppression):
    • E731: lambda → named function
    • E741: ambiguous variable name lline
    • E721: !=is not for type comparison
    • PLW1641: added __hash__ to MFCConfig dataclass
    • PLR1722: exit()sys.exit()
    • F541: removed extraneous f prefix from 40 f-strings without placeholders
    • E501: wrapped 2 long lines
    • E702: split semicolon-separated statements
    • PLW2901: renamed 6 overwritten loop variables
  • Dependencies: Replaced pylint and autopep8 with ruff in pyproject.toml.
  • Bug fix: lint.sh used $(pwd)/toolchain/ which resolved symlinks and broke ruff config discovery; switched to relative paths.

Config details (ruff.toml)

line-length = 200
target-version = "py39"
select = ["E", "F", "W", "I", "PL"]
ignore = ["PLR0911", "PLR0912", "PLR0913", "PLR0915", "PLR2004", "PLC0415"]

Per-file ignores for examples/ and benchmarks/ (permissive for user-facing case files).

Test plan

  • ./mfc.sh lint passes (ruff check clean + 165 unit tests)
  • ./mfc.sh format runs without errors
  • ./mfc.sh precheck passes all 5 checks (formatting, spelling, toolchain lint, source lint, doc references)
  • CI passes on all compiler configurations

🤖 Generated with Claude Code

@github-actions

This comment has been minimized.

- Replace autopep8 with ruff format, pylint with ruff check
- Add ruff.toml config at repo root (E, F, W, I, PL rule sets)
- Enable ruff check --fix in format.sh and lint.sh for safe auto-fixes
- Remove all ~229 inline pylint: disable comments
- Fix code violations: E731 (lambda), E741 (ambiguous var), E721 (type
  comparison), PLW1641 (hash), PLR1722 (sys.exit), F541 (f-string),
  E501 (line length), E702 (semicolons), PLW2901 (loop var overwrite)
- Add ~12 noqa comments for intentional global statements (PLW0603/PLW0602)
- Remove 8 zero-violation rules from ignore list to keep config minimal
- Fix lint.sh symlink path resolution breaking ruff config discovery
- Replace pylint and autopep8 deps with ruff in pyproject.toml

Resolves MFlowCode#1281

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

…-fix

- Add PLW0602 (global-variable-not-assigned) to ruff.toml ignore list
  instead of scattering noqa comments across ~19 call sites
- Change ruff check --fix to keep stderr visible (> /dev/null || true
  instead of > /dev/null 2>&1 || true) so config/invocation errors
  are not silently swallowed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

- Use dataclasses.fields() instead of dataclasses.asdict() in
  MFCConfig.__hash__ to avoid issues with nested types and sorted()
- Delete format_python.sh which is no longer referenced by anything

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

- Use ruff check --fix-only instead of --fix || true so genuine ruff
  failures propagate while still tolerating unfixable violations
- Update CLAUDE.md: Pylint -> Ruff in lint command description
- Add 4 unit tests for MFCConfig.__hash__ (hash/eq contract, set/dict usage)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Replace pylint + autopep8 with ruff for Python linting and formatting

1 participant