Skip to content

ci: Switch from flake8, isort and black to ruff#554

Merged
ValerianRey merged 15 commits intomainfrom
switch-to-ruff
Feb 4, 2026
Merged

ci: Switch from flake8, isort and black to ruff#554
ValerianRey merged 15 commits intomainfrom
switch-to-ruff

Conversation

@PierreQuinton
Copy link
Copy Markdown
Contributor

@PierreQuinton PierreQuinton commented Feb 3, 2026

Structural changes:

  • Add ruff dependency, configuration and pre-commit hook
  • Add ruff in the typing check and rename it code-quality
  • Remove check-todos (now done by ruff in CI)

Code changes to adapt to ruff:

  • Use strict=True when zipping
  • Use | None instead of Optional
  • Use | in isinstance instead of tuple
  • Rename unused for-loop counters to _
  • Stop using .format in strings
  • Stop importing Iterable and Callable from typing
  • Group "as" imports
  • Stop opening files explicitly with "r" mode

@PierreQuinton PierreQuinton added the cc: ci Conventional commit type for changes to the CI (Github workflows and actions). label Feb 3, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/torchjd/__init__.py 100.00% <100.00%> (ø)
src/torchjd/aggregation/_graddrop.py 100.00% <100.00%> (ø)
src/torchjd/aggregation/_mgda.py 100.00% <100.00%> (ø)
src/torchjd/aggregation/_utils/str.py 100.00% <100.00%> (ø)
src/torchjd/autogram/_gramian_accumulator.py 100.00% <100.00%> (ø)
src/torchjd/autogram/_gramian_computer.py 100.00% <100.00%> (ø)
src/torchjd/autogram/_module_hook_manager.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_jac.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_jac_to_grad.py 100.00% <100.00%> (ø)
src/torchjd/autojac/_mtl_backward.py 100.00% <ø> (ø)
... and 3 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PierreQuinton
Copy link
Copy Markdown
Contributor Author

PierreQuinton commented Feb 3, 2026

This is a bit annoying, we can't make the CI fail on TODOs while it work on local because we are using the precommit.ci app to do the check instead of using uv run ruff check --output-format=github (of course they have an output mode for Github). I think we should add an action to check ruff, and keep the pre-commit.ci to verify the rest of precommits. What do you think @ValerianRey ?

EDIT: This is what I did in the commits following this one, if we accept this, then we need to remove Absence of TODOs and Typing from the list of required checks, and add Check code correctness (better name needed).

PierreQuinton and others added 6 commits February 3, 2026 14:04
The reason we used strict=False was only that it's the default and it's
thus shorter to write. If we're forced to specify the `strict`
parameter, let's use `True`.
@ValerianRey
Copy link
Copy Markdown
Contributor

This is a bit annoying, we can't make the CI fail on TODOs while it work on local because we are using the precommit.ci app to do the check instead of using uv run ruff check --output-format=github (of course they have an output mode for Github). I think we should add an action to check ruff, and keep the pre-commit.ci to verify the rest of precommits. What do you think @ValerianRey ?

EDIT: This is what I did in the commits following this one, if we accept this, then we need to remove Absence of TODOs and Typing from the list of required checks, and add Check code correctness (better name needed).

I think what you did is perfect: having ruff run both in pre-commit hooks (so that we instantly block comitting if some formatting is wrong) and having it in the github action, so that we have the nicer formatting (mostly for when we somehow have pre-commit not installed because of an incomplete reinstallation, or for new contributors).

@ValerianRey
Copy link
Copy Markdown
Contributor

ValerianRey commented Feb 4, 2026

Really nice, LGTM

Even if it's just 1 second, it's noticeably faster to run the hooks locally.
Also the linting seems reasonably more strict, which is good.
And I like not having to rely on our own implementation of TODO checker anymore.

@ValerianRey ValerianRey changed the title ci: Switch to ruff ci: Switch from flake8, isort and black to ruff Feb 4, 2026
@ValerianRey ValerianRey merged commit b6880cd into main Feb 4, 2026
15 checks passed
@ValerianRey ValerianRey deleted the switch-to-ruff branch February 4, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: ci Conventional commit type for changes to the CI (Github workflows and actions).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants