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 4 commits intomllam:mainfrom
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
| dynamic = [ "version" ] | ||
| # PEP 621 project metadata | ||
| # See https://www.python.org/dev/peps/pep-0621/ | ||
| dependencies = [ |
There was a problem hiding this comment.
pillow disappeared from project.dependencies, but neural_lam/custom_loggers.py and neural_lam/models/ar_model.py still import PIL.Image. This turns a tooling-only PR into a packaging regression for fresh install
Replace separate black/isort/flake8 hooks with Ruff, add pyproject formatting plus explicit-noqa and branch-protection hooks, and keep phased rule ignores so we can tighten enforcement incrementally. Made-with: Cursor
Restore the missing pillow runtime dependency, align pylint ignore and Ruff isort settings with reviewer guidance, and apply the resulting lint-driven cleanup so the updated pre-commit stack passes consistently. Made-with: Cursor
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. |
Upgrade pyproject-fmt to a current release and apply its normalized pyproject formatting so the 3.14 pre-commit job no longer crashes and runs consistently across the matrix. Made-with: Cursor
There was a problem hiding this comment.
Thanks @Shivampal157. One item still open from the previous review, see inline.
| "UP045", # Optional/Union modernization deferred to follow-up cleanup | ||
| ] | ||
| lint.per-file-ignores."__init__.py" = [ "F401" ] | ||
| lint.isort.import-heading = { first-party = "First-party", standard-library = "Standard library", third-party = "Third-party" } |
There was a problem hiding this comment.
The old isort had import_heading_localfolder = "Local", which enforces the # Local marker before relative imports in ~18 modules. The new config covers first-party/standard-library/third-party but not local-folder, so # Local headings go unenforced.
| lint.isort.import-heading = { first-party = "First-party", standard-library = "Standard library", third-party = "Third-party" } | |
| lint.isort.import-heading = { first-party = "First-party", local-folder = "Local", standard-library = "Standard library", third-party = "Third-party" } |
There was a problem hiding this comment.
@sadamov thanks for pointing that out - I’ve now added local-folder = "Local" to the Ruff isort import-heading config in pyproject.toml and pushed the update
sadamov
left a comment
There was a problem hiding this comment.
please fix the final suggestions above then we wait for next dev-meeting
Include the Local section heading in Ruff isort import-heading config so existing relative-import heading conventions remain enforced. Made-with: Cursor
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