-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Replace black
formatter with ruff
#90457
Conversation
Messed up |
dd8ef3d
to
26bde93
Compare
You used a merge commit to update your branch, please use rebase in the future instead, see here |
a096ce9
to
f3b3abd
Compare
Holy hell, ruff is making an insanely good first impression! A linter/formatter that has the capability of recognizing SConstruct in editor without major tweaking is amazing. VSCode can even recognize a extend-exclude = ["thirdparty"]
extend-include = ["SConstruct", "SCSub"]
line-length = 120
target-version = "py38" |
6a05254
to
0664737
Compare
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.
After some adjustments to ensure this is synced with pyproject.toml
& suppressing certain rules in SConstruct
/SCsub
files, everything looks good to go!
We can revisit those suppressed rules once this is established as a baseline, probably around the same point we decide which extra rules we should enable.
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 quite nice!
@Repiteo's changes/additions lgtm! |
@@ -1465,14 +1460,14 @@ def format_key_value(v): | |||
if godot_platform != "windows": | |||
configurations += [ | |||
f'<ProjectConfiguration Include="editor|{proj_plat}">', | |||
f" <Configuration>editor</Configuration>", | |||
" <Configuration>editor</Configuration>", |
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.
That's technically correct, but a bit sad to lose the alignment.
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.
Nothing we can do I'm afraid, seems to be a shortcoming of idiomatic Python.
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.
This could use a multiline f-string, but I'm not sure this would make things much better for 3 lines (the big drawback of multiline strings is losing the indentation, which also looks bad). So I guess it's fine as is.
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.
One other way of solving this would be to drop f-strings in this instance altogether:
if godot_platform != "windows":
configurations += [
'<ProjectConfiguration Include="editor|' + proj_plat + '">',
" <Configuration>editor</Configuration>",
" <Platform>" + proj_plat + "</Platform>",
"</ProjectConfiguration>",
]
Though that would probably raise a warning about not using f-strings, so there's no winning here.
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 good to me overall.
Tested locally, it works as expected. I suggest adding this in [tool.ruff.lint]
extend-select = [
"I", # isort
] This way, contributors won't need to install isort separately anymore. |
|
||
[tool.ruff.lint] | ||
extend-select = [ | ||
"I", # isort |
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 think that also some other usable rule groups could be enabled here in this or other MR - https://docs.astral.sh/ruff/rules/ like:
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.
Let's assess those in a follow-up PR, I think this one is big enough for now :)
import os | ||
|
||
import core_builders | ||
|
||
import methods |
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.
Is this done by isort
? What's the rule applied here?
It makes sense to me to separate stdlib imports from our local ones, but I'd then expect core_builders
and methods
to be adjacent, not separated.
Or is it because core_builders
is actually local (relative path) and methods
was added to sys.path
?
Thanks! |
## Summary - Ever since godotengine/godot#90457 was merged into the `master` branch, Godot has been using ruff for linting and formatting Python files. As such, this PR adds Godot to the "Who's Using Ruff?" section of the main `README.md` file. ## Test Plan - N/A
This is causing issues on macOS, since the downloaded |
This PR replaces
black
static checking suite withruff
.It's a pretty big change, and I understand it warrants discussion, which I welcome and look forward to.
The basic premise of this change is that the
ruff
linter and formatter is slowly creeping its way to becoming the new standard - more importantly, it promises orders of magnitude better performance than previously available solutions.If this is a welcome change we might want to also update Godot's code style guidelines doc entry.
From
ruff
's README file:pip
pyproject.toml
supportLocal usage ought to be similar to that of
black
: