Modernize linting stack: migrate to Ruff and streamline pre-commit hooks#614
Modernize linting stack: migrate to Ruff and streamline pre-commit hooks#614Shivampal157 wants to merge 1 commit into
Conversation
096e65b to
d62a12f
Compare
|
@sadamov ,thanks for assigning this. moved black/isort/flake8 to Ruff I also cleaned the branch so only these toolchain/config changes are in this PR. |
There was a problem hiding this comment.
Thanks! Overall direction is good. Please run the re-commits and pytest locally they are currently broken.
| Old tool | Replaced by | Notes |
|---|---|---|
black |
ruff-format |
line-length 80 preserved |
isort |
ruff I rules |
import sorting only; heading comments not enforced (see below) |
flake8 E/F/W |
ruff E/F/W |
same rules; E203 and F401/__init__.py ignores preserved |
flake8 W503 |
not needed | ruff formatter enforces one style; rule not implemented |
flake8 I002 |
not needed | flake8-isort-specific; no equivalent in ruff |
New rule families added that were not in the old setup: G (logging format), PT
(pytest style), PTH (pathlib), S (bandit), TCH (type-checking imports), UP
(pyupgrade). Most are gated behind per-rule ignores for incremental tightening.
TB Fixed
1. Dangling # Pylint config comment
pyproject-fmt moved the pylint sections up but left the preceding comment orphaned at
the very bottom of the file after [tool.codespell]. Delete
2. pylint ignore pointed at non-existent file
- "create_mesh.py", # Disable linting for now, as major rework is planned/expected
+ "create_graph.py", # Disable linting for now, as major rework is planned/expected
create_mesh.py does not exist; Bug predates this PR
3. isort known-first-party made explicit
Added [tool.ruff.lint.isort] with known-first-party = ["neural_lam", "tests"].
Ruff auto-detects these when run from the project root, but being explicit avoids
surprises when ruff is invoked in other contexts (CI steps, editors, /tmp test files).
The old isort config also enforced import section heading comments (# Standard library, # Third-party, etc.) via import_heading_*. Ruff supports the equivalent
(import-heading.*) but enabling it today would fail on a stray blank line within the
third-party block in several test files. Fix and activate the rule please.
4. Python 3.13 classifier needs CI coverage
pyproject-fmt auto-injected "Programming Language :: Python :: 3.13". No CI matrix
currently tests against 3.13. Either add a 3.13 job to the workflow or remove the
classifier.
4. CHANGELOG entry missing
Needs a maintenance entry before merge.
5. Branch not up to date with main
Should be rebased before merge.
|
Hey @Shivampal157, thanks for picking this up! I was actually gonna grab this issue but my thoughts are the same which u did.
import-heading-stdlib = "Standard library"
import-heading-thirdparty = "Third-party"
import-heading-firstparty = "First-party"Then just run
Lmk if the Ruff auto-fix gives you any trouble! cc : @sadamov |
kshirajahere
left a comment
There was a problem hiding this comment.
@sadamov covered most of the things about the broken pre-commits ;). Leaving one comment about a missing dependency
c95705f to
f2df692
Compare
|
@sadamov @kshirajahere addressed the requested updates and pushed the latest changes: switched pylint ignore to create_graph.py, added Ruff isort config (known-first-party, import-heading), replaced blanket # noqa with explicit suppressions, restored pillow dependency, added the changelog entry, rebased on latest main, resolved the tests/test_plotting.py conflict, and re-ran pre-commit --all-files (passing). please let me know if you’d like any further changes. |
There was a problem hiding this comment.
Thanks @Shivampal157. One item still open from the previous review, see inline.
sadamov
left a comment
There was a problem hiding this comment.
please fix the final suggestions above then we wait for next dev-meeting
3cb7175 to
88204f1
Compare
Migrate from black/isort/flake8 to Ruff for both linting and formatting, keeping line-length 80 and existing ignore semantics (E203, F401 on __init__). Add pyproject-fmt, python-check-blanket-noqa, and no-commit-to-branch pre-commit hooks. Defer pathlib (PTH103/118/123) and typing modernization (UP006/007/022/035/045) to follow-up cleanup via per-rule ignores. Reformat the post-mllam#208/mllam#507/mllam#239 codebase with ruff-format and apply ruff-check --fix; manually convert one remaining lambda in step_predictors/base.py to a def (E731) and split a compound assert in test_gnn_layers.py (PT018). Co-Authored-By: Shivam Pal <Shivampal157@users.noreply.github.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
88204f1 to
75d8d0c
Compare
|
OK I kept all the thematic changes from this PR but reran the pre-commits with ruff for all files, starting from the main branch after #208 was merged. Now it's ready to be merged once v0.7.0 lands. |
Describe your changes
Switched the lint/format setup to Ruff and cleaned up pre-commit accordingly.
I removed the separate
black,isort, andflake8hooks and replaced them with Ruff (ruff-check+ruff-format). I also added a few small pre-commit checks we discussed in #601:pyproject-fmtpython-check-blanket-noqano-commit-to-branch(main)I kept the stricter rule families configured but with targeted ignores where the repo is not ready yet, so we can tighten them in follow-up PRs without blocking contributors now.
I then ran pre-commit on all files and fixed what was needed so the hook suite is green.
Dependencies required for this change:
Issue Link
Part of #601
Type of change
Checklist before requesting a review
pullwith--rebaseoption if possible).Checklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
reflecting type of change (add section where missing):
Checklist for assignee
closes #601