-
Notifications
You must be signed in to change notification settings - Fork 44
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruff: smaller steps #364
base: main
Are you sure you want to change the base?
Ruff: smaller steps #364
Conversation
@rcomer Thanks for this 馃殌 I was waiting for SciTools/iris#5254 to conclude, then reopen SciTools/iris#353, but totally happy to replace it with this 馃憤 |
9b32f11
to
4e7683a
Compare
Rebased, updated the ruff version and replaced black with ruff's formatter. Swapping black for ruff's formatter only affects one line, shown in the most recent commit. We now have more failures and fewer autofixes from main ruff. I think because some fixes that were previously done automatically are now marked "unsafe" so we would need to manually opt in (see https://astral.sh/blog/ruff-v0.1.0#respecting-fix-safety). |
I applied the "unsafe" fixes but then tweaked a few that didn't look quite right to me. Also tidied up the remaining errors so I think this is now ready for review. Unlike most of my branches, the individual commits here may be meaningful enough to review individually. |
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.
Looks like a good improvement to me.
(I doubt I will get a chance to follow-up, but hopefully my review moves the PR forwards 馃槈
@@ -1,6 +1,6 @@ | |||
# Generated from /home/ruth/git_stuff/cf-units/cf_units/_udunits2_parser/parser/udunits2Lexer.g4 by ANTLR 4.11.1 |
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.
Not sure we should be re-formatting this (since it is auto-generated)? Perhaps add an exception to the pre-commit config.
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.
I wondered the same when these files were blackened at #368. Here, though, the code changes in udunits2Parser.py seem correct to me. Might be worth skipping the line length rule so we don鈥檛 have to manually wrangle the comments in future though 馃.
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.
I have skipped the line length rule for these files.
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.
Thanks @pelson - great to hear from you again! I will follow up more when I am back on my work machine.
@@ -1,6 +1,6 @@ | |||
# Generated from /home/ruth/git_stuff/cf-units/cf_units/_udunits2_parser/parser/udunits2Lexer.g4 by ANTLR 4.11.1 |
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.
I wondered the same when these files were blackened at #368. Here, though, the code changes in udunits2Parser.py seem correct to me. Might be worth skipping the line length rule so we don鈥檛 have to manually wrangle the comments in future though 馃.
New commit dismissed an approving review. Not seen that before 馃槙 |
@@ -1,6 +1,6 @@ | |||
# Generated from /home/ruth/git_stuff/cf-units/cf_units/_udunits2_parser/parser/udunits2Lexer.g4 by ANTLR 4.11.1 | |||
# Generated from cf_units/_udunits2_parser/parser/udunits2Lexer.g4 by |
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.
Still changes to auto-generated files - would suggest not making any changes to auto-regeneratable files. (everything in _udunits2_parser.parswr
)
verbose = "False" | ||
[tool.ruff.per-file-ignores] | ||
# Allow the longer comment lines that the generated code produces. | ||
"cf_units/_udunits2_parser/parser/*.py" = ["E501"] |
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.
The alternative way of blanket ignoring everything with ruff-formatter is to put this exclude in pre-commit
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.
To be clear, the changes in these files came from the ruff linter (which has some auto-fixes) rather than ruff formatter.
I have no objection to skipping linting/formatting for these files but, since they were previously flake8-linted and black-formatted I feel like that decision has already been made for the current generation. If whoever does the next re-generation wants to turn off the linting and their reviewer agrees then that's a decision for then.
馃殌 Pull Request
Description
SciTools/iris#353 proposed introducing ruff to cf-units for linting, but also changed some style choices (max line length and import sort order). IMO this made it difficult to spot what effect ruff was having on the code. This PR breaks it down so hopefully it's easier to see what's going on:
dict(...)
to{...}
- maybe for speed?if thing == None
toif thing is None
- I'm surprisedflake8
didn't catch that oneCI will fail with remaining problems that ruff found: