style: migrate to `ruff`
astral-sh/ruff has emerged as a competitor to the existing linters. It's considerably faster than the current linter pylint viz.
Source: ruff repository
Switching to ruff would enable us to switch to a single tool, as it has drop-in parity with black, isort and support for pylint rules.
Happy to open a PR if interested 😄
References:
- https://github.com/astral-sh/ruff/issues/689
Great idea, we already use ruff internally. We'd welcome a PR.
I would like to contribute.
@TakshPanchal sounds good, LMK if you need any help with the PR
Currently, isort and black is being used right? So I have to pylintrc as reference config. From docs,
Ruff can be configured through a
pyproject.toml,ruff.toml, or.ruff.tomlfile.
So majorly I have to convert pylintrc with one of these file right?
Currently,
isortandblackis being used right? So I have topylintrcas reference config. From docs,Ruff can be configured through a
pyproject.toml,ruff.toml, or.ruff.tomlfile.So majorly I have to convert
pylintrcwith one of these file right?
Yes, and let's stick with one single configuration file, so convert pylintrc to a ruff configuration within pyproject.toml.
Ideally the changes lead to no style changes, i.e. running make lint with ruff leads to no changes in code files.
can I work on this issue?
Sure, we only assign one issue at a time. So, I'll assign this issue for now. If you want to work on some other issue first, let me know.
@Abhrajitdas02 would you like any help with this issue?
@guarin I was working on this and noticed that we actually don't enforce pylint anywhere.
Source: https://github.com/search?q=repo%3Alightly-ai%2Flightly%20pylint&type=code
Hi there, I was looking into this and thinking of picking it up. But before opening a PR I'd like to settle the question @SauravMaheshkar raised above, since it changes the scope of the PR.
Current state of the toolchain (verified against master) :
blackandisortare enforced in CI viamake format-checkin.github/workflows/test_code_format.yml.pylintis defined in theMakefile(lint,lint-lightly,lint-tests) and listed as adevdependency, but no workflow ever calls it,grep -ri lint .github/workflows/returns nothing. Thepylintrcis effectively dead config: most of itsdisable=list is Python 2/3 compat cruft, andmax-line-length=88already matches black's default.- One lonely
# pylint: disable=broad-exceptpragma inlightly/api/api_workflow_download_dataset.py.
So the original framing ("convert pylintrc to ruff config, no style changes") doesn't quite map onto reality as there's no enforced lint config to preserve parity with. The real decision is:
- Option A: like-for-like, no enforcement change. Ruff replaces
black+isortinmake format-check; ruff also replacespylintinmake lintbutmake lintstays uncalled by CI. Conservative ruleset (E,F,W,I- pycodestyle errors/warnings, pyflakes, isort) so the PR produces zero code diffs. Smallest, easiest to review, matches the original "no style changes" goal. - Option B: start enforcing lint. Same as A, plus wire
make lint(or fold it intoformat-check) intotest_code_format.yml. Higher value, but likely surfaces latent issues that need fixing in the same PR.
I'd lean towards Option A as a clean, mergeable first step, with enforcement as a follow-up. What do you think? @guarin
Either way the PR would touch:
pyproject.toml(dropblack/isort/pylintdeps + their[tool.*]sections, add[tool.ruff]with the sameopenapi_generatedexclusion andtarget-version = "py37"to match the CI matrix),Makefile(rewriteformat/format-check/lint),.pre-commit-config.yaml(replacenbqa-black/nbqa-isortwithruff-pre-commit, ruff has native.ipynbsupport so the nbQA wrappers aren't needed),- delete
pylintrcand remove the lone pylint pragma.
I'd lean towards Option A as a clean, mergeable first step, with enforcement as a follow-up. What do you think? @guarin
While reading on some other open issues, I found the answer (Option A) in this comment. Before I start working on it, could you please assign this issue to me? and please feel free to let me know if you have any feedback on my approach/analysis from the above comment. Thanks!
Hi @RecreationalMath, Thanks for the good breakdown into options. I would also suggest to go forward with option A for now. We can then later progressively add a broader ruleset if we feel the necessity (probably not enforcing it on all modules at the same time), but iteratively to keep the diffs manageable per PR. This then lets us eventually also add it to CI (which is indeed a pity that it isn't yet). I think that approach matches @guarin's proposed timeline. I am assigning the issue to you!
I have been doing some digging on the comparison between ruff and black, and it's worth noting that ruff's formatter has some known, documented differences from black. The ruff project documents these known deviations from Black here and states that >99.9% of lines are formatted identically on large Black-formatted projects.
That still leaves 0.1%, which may manifest as a one-time normalisation cost within the same PR. Just a heads up, as this will translate to review overhead for the maintainers/reviewers.
Thanks for the heads-up! Let's see how many diff files it generates. But since it's going to be formatting and linting, it should anyway be reasonably fast to review.
You might want to throw in a .git-blame-ignore-revs file if the diff is too large
You might want to throw in a
.git-blame-ignore-revsfile if the diff is too large
It is indeed too large, ~96 files. Added .git-blame-ignore-revs.