-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
Add exit-non-zero-on-fix support for fix and fmt goals #20905
Comments
Summary: there's a way we could implement this for specific goals that'd handle the problem "locally", but maybe there's a bigger picture way to handle this. To implement this for both pants/src/python/pants/core/goals/fix.py Line 370 in 3ef507e
We could, hypothetically:
However, I'm not sure that's the perfect approach, for two reasons:
So, I think that suggests two options to me:
@stuhood does that last option sound reasonable? If so, any tips for implementing? |
Don't all formatters and fixers already have a Pants-level "check but don't edit" mode, for CI? I thought @thejcannon implemented this a while ago. |
Yeah that's |
So sounds like just running lint in CI will have the desired effect? It
runs all fixers and formatters?
…On Mon, May 13, 2024, 8:27 AM Josh Cannon ***@***.***> wrote:
Don't all formatters and fixers already have a Pants-level "check but
don't edit" mode, for CI? I thought @thejcannon
<https://github.com/thejcannon> implemented this a while ago.
Yeah that's lint 😅
—
Reply to this email directly, view it on GitHub
<#20905 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAD5F7HSMYCYVE3ANCJ3P2TZCDLWRAVCNFSM6AAAAABHQ4W5OSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBXHE4TQNRXHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
It doesn't offer the desired effect. On git hooks we want to apply all fixes and formatting but have a non-zero exit code. This is so the developer can include the fixes prior to pushing to CI. |
|
For my use of something similar, the desired workflow is:
I've switched to running read-only |
Yeah this exactly what are facing too. We would like to apply the fixes automatically so the developers do not have to run an additional commit to perform the fmt / fixes. At this point the fixes / fmting should be staged so they can review / commit. |
@benjyw This is for running git hooks, in CI we already do this workflow. |
Ah, gotcha! So this is for running on desktops. OK, so that option makes sense. Could be on the |
Happy to take this task on. For the two options on how to implement from the parent comment:
I think I can definitely implement the first option, but not sure how the second would work. It certainly seems like the snapshot could be really expensive if the repo size is large, and the individual goals may have smaller target sets compared to an entire buildroot. |
Is your feature request related to a problem? Please describe.
We want to use Pants for various linting/formatting checks, including in a pre-commit hook. One challenge with Pants in that workflow is when we run
pants fix fmt lint
and it applies autofixes it doesn't exit with 1. We need pre-commit to fail so the developer has a chance to include those fixes in the commit.By contrast, ruff has a --exit-non-zero-on-fix flag which allows this to be differentiated.
Describe the solution you'd like
Maybe some global setting like
pants --exit-non-zero-on-fix fix fmt
Then when autoformating or autofixing occurs the exit code is non-zero failing notifying the caller there were some issues.
Describe alternatives you've considered
Inspecting changed files and parsing output from pants. This is not ideal.
I guess we could do
pants lint fix fmt
as long as it runslint
first then the next goals. However, the output can be confusing for developers if some lint failures were autofixed.The text was updated successfully, but these errors were encountered: