-
Notifications
You must be signed in to change notification settings - Fork 5
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
Linting and formatting with Ruff #56
Conversation
bdac872
to
eedfd21
Compare
Just a short comment. @Chroxvi is on vacation and is back in two weeks. I really want him to do the review. Sorry for letting you wait until he is back. |
Gentle nudge (as I too am back from vacation) :) |
@akx Thanks a lot for this contribution - and sorry for not getting back to you any sooner. A pre-commit linting setup for cotainr has been on my wishlist for quite some time, so let's get this rolling! The cotainr style guide states that we use black for code formatting, numpydoc for formatting docstrings, and in general adhere to PEP8. In addition to that I have locally been using isort, flake8 and mypy (though mypy doesn't make much sense before we add type annotations to cotainr). I don't have a strong opinion on any particular tool, so we can introduce ruff, if you thing that is the best suitable tool for such a pre-commit linting setup. Given the high level of compatibility in formatting between ruff and black, I think it is acceptable to switch to ruff for formatting. Would you agree that ruff is a viable solution to replace my setup with black, isort, flake8, and mypy? And do we need any additional configuration of ruff to better align with what has been the implicit standards in cotainr so far? My only concern here is to introduce too many code changes that are only related to formatting since it kind of destroys the git history. |
Ruff doesn't do actual type-checking, so it doesn't replace For the other tools, yes (disclaimer: I'm an early minor contributor to Ruff). It's a lot faster than the other tools combined (so it stays out of your way, as it were, and is more eco friendly too) :)
More rules could be enabled in a follow-up PR to make things stricter. Ruff can also be configured to enforce
Since ruff-format and Black are practically the same thing (aside from ruff-format doing a better job (IMO) in certain corner cases), I don't think that's an issue here. The auto-format commit itself is quite short: 96f63ab This PR could be merged with a regular merge commit, and that commit added to |
I |
eedfd21
to
84ea641
Compare
d27d179
to
35c9614
Compare
@akx Excellent, that helps a lot! At this point, I think it is entirely up to me move this forward. Sorry for not getting back to you sooner. I hope to be able to move this forward this week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I finally got around to digging into this PR. I still very much the idea of introducing Ruff for linting and formatting!
Having looked more into it, I am a bit more hesitant to also introduce pre-commit - see my specific review comment about this. @akx, I would like your opinion on this.
I have suggested an extended list of Ruff rules to enable based on the linting done by my editor - this may be too many rules to enable for now.
The rest is just a bunch of minor comments and suggestions for improvements.
Finally, when we get to #57, I think we should move the ruff.toml config to pyproject.toml since we are already collecting all other configuration in pyproject.toml. For now, though, lets use the ruff.toml config file.
769eed3
to
533949f
Compare
@akx I think the main missing part here is handling my comments related to adding more details about this linting setup to the documentation. Would you be willing to add these? If not, I am also very happy to merge this PR once the details in the other few remaining comments have been sorted out. |
533949f
to
a240e13
Compare
Done deal. To keep this more reviewable, I can follow this up after merging with another PR that adds more |
b88ad5f
to
684bf38
Compare
Co-authored-by: Christian Schou Oxvig <5367057+Chroxvi@users.noreply.github.com>
684bf38
to
5b3f210
Compare
Excellent! I'll merge this now. @akx Thanks for a lot for hanging in here and for all the valuable discussions around best practices for using Ruff, pre-commit, and GitHub actions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved!
This PR enables linting using Ruff via pre-commit (which also runs these lints in CI).
The ruff.toml configuration file is rather conservative at this point; more lint families can be added as required. The line-length of 88 characters was chosen by checking which common line-length causes the shortest
ruff format
delta.