GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing github.com — GH-121970: Use Ruff to check and format the docs tools by AA-Turner · Pull Request #122018 · python/cpython Conversation
|
Me too! Note there's some overlap with #121241 which @AlexWaygood wanted to post about on Discourse first. I'm also fine with not doing so. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Is that the right issue/PR? I don't see a mention of Ruff on it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I'm specifically nervous about enabling more aggressive linting on stdlib modules in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would personally go for quote-style = "preserve", and switch to quote-style = "double" in a followup, rather than going for quote-style = "single" (https://github.com/python/cpython/pull/122018/files#r1684185495). But I don't feel strongly. LGTM!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @AA-Turner, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @AA-Turner, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @AA-Turner, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…H-122018) (cherry picked from commit 40855f3) Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
|
GH-122023 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-122024 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ythonGH-122018) (cherry picked from commit 40855f3) Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
) (#122024) (cherry picked from commit 40855f3) Co-authored-by: Alex Waygood <[email protected]>
) (#122023) GH-121970: Use Ruff to check and format the docs tools (GH-122018) (cherry picked from commit 40855f3) Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
|
No problem :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I got a lint failure on a PR: As far as I know, the import block is OK according to PEP 8. When adding checks like this, could you also add some instructions to the devguide about how to deal with the warnings -- preferably without installing third-party tools I might not trust? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@encukou, I'm sorry if we rushed this. Sorry that the error was inscrutable; thanks for flagging.
We already have documentation in the devguide noting that we have pre-commit checks set up, and giving some instructions about setting up pre-commit locally:
(I personally tend to avoid actually installing pre-commit hooks myself -- I usually run
Our CI is setup so that generally pre-commit will show you the changes it wants you to make to your PR as a diff when CI fails. In this case, it looks like that didn't happen for #121278. I'm not sure why that is, but anyway -- it's telling you that your imports aren't alphabetically sorted. You can find the documentation for the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Thanks! I filed python/devguide#1360 to improve the set-up instructions. (If you don't do it yourself, is installing pre-commit as a commit hook the right thing to do?)
I don't understand why it is important to sort imports alphabetically. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
It's a thing that many people like to do. The advantage is that you don't have to run the linter manually; it automatically applies any autofixes as part of running I wasn't involved in the decision to add a section to the devguide telling people to setup commit hooks to run pre-commit.
It's not particularly important, but many people have decided that it's something they want to enforce as a matter of style. I personally like to enforce a consistent style of imports in this way in the projects I maintain, but I also wouldn't be distraught if we got rid of this rule.
PEP 8 is the style guide for the standard library, and we're not enforcing this rule on the standard library -- only internal tooling in the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| name: Run Ruff (lint) on Argument Clinic | ||
| args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml] | ||
| files: ^Tools/clinic/|Lib/test/test_clinic.py | ||
| - id: ruff-format |
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The Ruff pre-commit README says:
When running with
--fix, Ruff's lint hook should be placed before Ruff's formatter hook, and before Black, isort, and other formatting tools, as Ruff's fix behavior can output code changes that require reformatting.When running without
--fix, Ruff's formatter hook can be placed before or after Ruff's lint hook.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Same here on both counts. Alphabetical import sorting can be more useful, than for example, new imports being tacked onto the end:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
But as a contributor to various projects, each of which expects or enforces a slightly different code style (and most of which expect me to format the code), I get the opposite of consistency. If alphabetical import sorting is useful, I do think it should be preferred for new code across the entire project. Then, it would be easier to accept that in some parts of the code we enforce some parts of the style guide. It worries me to see a maintainer that has things set up just right, slightly differently than what's in the docs, while others get an inscrutable error for what should be a simple contribution. Should we be worried about non-dogfooded devguide instructions? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.