-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
GH-121970: Use Ruff to check and format the docs tools #122018
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e2026b9
GH-121970: Use Ruff to check and format the docs tools
AA-Turner a882565
Add ruff-format pre-commit
AA-Turner 13cb3f3
Disable E501
AA-Turner 933095c
Try pre-commit with '--check'
AA-Turner a9228fe
Remove flake8-errmsg
AA-Turner efbee68
Revert the version bump (new Lib/test failures)
AA-Turner 7bd87a3
Update comments in .ruff.toml
AA-Turner 65ceaa5
Resolve Alex's notes
AA-Turner 9e95b25
Resolve Hugo's notes
AA-Turner 8fa92b5
Merge branch 'main' into docs/use-ruff
AA-Turner dc85abe
Reformat with new settings
AA-Turner a599ef7
Use quoute-style=preserve
AA-Turner 7831456
Preserve even more
AA-Turner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
target-version = "py312" # Align with the version in oldest_supported_sphinx | ||
fix = true | ||
output-format = "full" | ||
line-length = 79 | ||
extend-exclude = [ | ||
"includes/*", | ||
# Temporary exclusions: | ||
"tools/extensions/c_annotations.py", | ||
"tools/extensions/escape4chm.py", | ||
"tools/extensions/patchlevel.py", | ||
"tools/extensions/pyspecific.py", | ||
] | ||
|
||
[lint] | ||
preview = true | ||
select = [ | ||
"C4", # flake8-comprehensions | ||
"B", # flake8-bugbear | ||
"E", # pycodestyle | ||
"F", # pyflakes | ||
"FA", # flake8-future-annotations | ||
"FLY", # flynt | ||
"FURB", # refurb | ||
"G", # flake8-logging-format | ||
"I", # isort | ||
"LOG", # flake8-logging | ||
"N", # pep8-naming | ||
"PERF", # perflint | ||
"PGH", # pygrep-hooks | ||
"PT", # flake8-pytest-style | ||
"TCH", # flake8-type-checking | ||
"UP", # pyupgrade | ||
"W", # pycodestyle | ||
] | ||
ignore = [ | ||
"E501", # Ignore line length errors (we use auto-formatting) | ||
] | ||
|
||
[format] | ||
AA-Turner marked this conversation as resolved.
Show resolved
Hide resolved
AA-Turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
preview = true | ||
quote-style = "preserve" | ||
docstring-code-format = true | ||
exclude = [ | ||
"tools/extensions/lexers/*", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@AA-Turner in pre-commit, it's usually best to put formatters before linters. This is because if there's a rule violation that linter shows, it will then show up as two different broken checks. It's also more important for the post-format version to be checked rather than showing errors on things that then get changed/relocated.
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.
Oh, are the pre-commit tools not idempotent? I hadn't realised that order mattered, as I thought we'd configured them to check only in a read-only fashion.
As you can probably tell, I don't use pre-commit personally!
A
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 Ruff pre-commit README says:
https://github.com/astral-sh/ruff-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.
@AA-Turner oh, I didn't realize. It's so popular that I tend to forget there's people who don't use it. I think I first contributed to pre-commit in 2016…
But yeah, there's science to crafting a config for the pre-commit tool. And there are a few principles I found very useful in this context. Here's how I sort the entries:
pre-commit itself does not modify things by itself, so you can say it's idempotent in this sense. It's the checks that call other tools that modify files. I think if a check changes files (pre-commit docs sometimes call these “fixers”, not “formatters”), pre-commit will then show that entry as failed (although, it probably relies on the called program's return code). When something changed, it's useful to know what, so it's best to call the tool with
--show-diff-on-failure
. I think the https://pre-commit.ci web service does this by default (this service is also able to push a commit with the changed files back to pull requests, by the way). Some people only use this CLI flag in CI, while others stick it into the command runner like tox so it's active locally when the contributors run linting.Feel free to tag me for reviews in future PRs if you need any more insight on this topic.