-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Introduce ruff
code-format style
#934
base: master
Are you sure you want to change the base?
Conversation
ruff
formatting, and replace flake8
linting with ruff
lintingruff
formatting, and replace flake8
linting with ruff
linting
I like the plan! Can we discuss this after we're done with steering committee prep? |
Absolutely. We may even want to delay this until after v0.4, depending on if it introduces difficulties cleaning up the outstanding PRs. |
@asoplata lot of points to think about :) I'm fine with using |
Btw, |
Thanks for your insight Mainak! Seeing how MNE does it will be an excellent reference point. Regarding linting, as you're probably aware (and what my commits in this PR made more confusing), the linting of Regarding formatting, I definitely understand that Godzilla-sized, N x kloc PR diffs are not good practice, but I think that any instance of switching from just the pretty-loose I experimented with running I will definitely make a new issue about using |
Can you explain the difference between formatting and linting? How can we explain to new contributors how to use ruff? e.g., is there a VSCode plug in etc? Should be added to contributing guidelines. I would split this PR into two. The first one just introduces ruff with roughly the same issues as flake8. Use ignore rules. In this PR you would make sure that everything is in place for people to migrate to ruff. The contributing guide should be updated and make sure that any other open PRs that may be affected are either closed or merged. The diff of this PR should be relatively small. This way you avoid rebase issues. In the next PR, remove the ignore rules and make ruff more strict. This PR should be turned around fast so that people working on new PRs start from the new codebase. |
I will separate the linting part of this PR into its own, since 1. the linting is a very small change, 2. formatting is a much, much bigger change, and 3. I do not think we should merge the formatting change at this time, and instead wait until everything required for I will return to this PR and explain the difference at a later date. |
I think we should use this PR as the main place to discuss agreeing upon a code Formatting-style . I will split changing our linter from To actually define what I mean by a code "Formatting-style", and to avoid the inevitable word count limitations, I've written a Gist instead explaining how we could consider defining and communicating about Linting vs Formatting vs "Programming Style Guides", including with examples: https://gist.github.com/asoplata/8bb94707810218df95dacaaaaf34bccb . |
ruff
formatting, and replace flake8
linting with ruff
lintingruff
code-format style
This is a PR for both introducing stylistic formatting using the incredibly fast
ruff
package (see https://docs.astral.sh/ruff/ ), and replacing ourflake8
linting also with the linting provided byruff
. This will result in very many lines of code changes, but should not affect functionality at all.Some of us were recently discussing if we should adopt a particular style, especially since the code right now is inconsistent. I think this is an opportunity to introduce
ruff
into the dev pipeline, both as our formatter of choice, and as our linter of choice (replacingflake8
). Pros of this approach:ruff
is unbelievably fast, both at formatting (both detecting and applying/editing format changes in-place) and linting. Our codebase is relatively small, but IMHO it is effectively instantaneous when I try it on both of these tasks, even on a 5-year-old Intel i5 processor.ruff
's formatting, which I think is identical toblack
's by default (e.g. line length 88 chars, etc.). Currently in this PR, the only non-default format style change is my preference for single quotes instead of double. Note that the longer line length is in line (pun intended) with other users ofruff
like Scipy (see https://scipy.github.io/devdocs/dev/contributor/pep8.html#pep8-and-scipy ). I personally prefer the C-style braces and emphasis on verticality, but whatever style we decide needs to be a group decision.ruff
's formatting is very configurable. We can easily make changes to our preferred format style.flake8
will actually edit your code to match particular formatting (whichruff
does). As far as I can tell,flake8
can only inform you of certain formatting findings (but will not edit your code). I could be wrong here. Ifflake8
cannot edit the formatting of our code, then we will need to install or setup another package to do that anyways (so it might as well beruff
).ruff
's linting can be set to automatically fix individual issues. I don't know ifflake8
supports this. I personally prefer to make the fixes myself so I understand them, but it's convenient.ruff
's linting is also extremely fast and configurable.ruff
doesn't currently have 100% support ofpycodestyle
rules (see Implement remainingpycodestyle
rules astral-sh/ruff#2402 ), but the vast majority are there, and it's definitely enough coverage to make it worth using.Finally, I will note that after creating the huge-formatting-commit, I ran all the tests locally and they passed, and I also successfully rebuilt the docs locally just in case as well.
If we want, we can use this PR for discussing format changes we want to make, that way I can rebase them on this branch and refrain from polluting the master branch with changes until we're happy.
I will also use this PR to get
ruff
's linting up and running, both fixing issues thatflake8
missed, and ensuring the CI runs ofruff
's linting work.