better-van-82973
11/10/2023, 4:12 PMancient-vegetable-10556
11/10/2023, 4:47 PMruff modes?better-van-82973
11/10/2023, 4:49 PMskip flag: https://github.com/pantsbuild/pants/blob/9adee6d33afccc657175c3d2d7abd4dc33c92745/src/python/pants/backend/python/lint/ruff/subsystem.py#L56
My main idea was to break this flag into two separate flags to skip formatting and linting, and default the formatting one to true instead of false. This would mean that people don’t suddenly overnight get opted into Ruff formatting if they don’t want it.
Does that make sense, or is there a better way?ancient-vegetable-10556
11/10/2023, 4:50 PM--ruff-modes= which would let you specify one or more of lint, fmt and fix. If unspecified, it would run all three.better-van-82973
11/10/2023, 4:51 PMskip flag (if at all)?ancient-vegetable-10556
11/10/2023, 4:51 PMbetter-van-82973
11/10/2023, 4:52 PMancient-vegetable-10556
11/10/2023, 4:52 PMskip isn't a flag, it's a field that you can declare on a single python_source target in order to have ruff not run on that sourceancient-vegetable-10556
11/10/2023, 4:53 PM--ruff-modes would affect how ruff runs globallyancient-vegetable-10556
11/10/2023, 4:53 PMbetter-van-82973
11/10/2023, 4:53 PMskip_ruff and can be applied to Python sourcesancient-vegetable-10556
11/10/2023, 4:53 PMSkipOptionbetter-van-82973
11/10/2023, 4:53 PMancient-vegetable-10556
11/10/2023, 4:54 PMskip in subsystem.pyancient-vegetable-10556
11/10/2023, 4:55 PMcue if you want an example: https://github.com/pantsbuild/pants/blob/9adee6d33afccc657175c3d2d7abd4dc33c92745/src/python/pants/backend/cue/subsystem.py#L40ancient-vegetable-10556
11/10/2023, 4:58 PMbetter-van-82973
11/10/2023, 4:58 PMskip flag does not let you selectively skip tasks, and if we were to modify it similar to cue then we’d end up skipping all Ruff tasks rather than just formattingancient-vegetable-10556
11/10/2023, 4:58 PMbetter-van-82973
11/10/2023, 4:59 PMskip option into separate options for each goal (fmt, lint, fix)better-van-82973
11/10/2023, 5:00 PMskip option for fmt to be true, and this would solve the issue by not automatically opting the end user into Ruff formattingancient-vegetable-10556
11/10/2023, 5:02 PMSkipOption doesn't work that way already.better-van-82973
11/10/2023, 5:09 PMancient-vegetable-10556
11/10/2023, 5:10 PM--ruff-modes would work well. --ruff-skip will need to stick around because of our deprecation policy, which is a bit annoyingancient-vegetable-10556
11/10/2023, 5:11 PMSkipOption and the existing ruff integration, I think he'll have better answers than mecurved-television-6568
11/10/2023, 6:16 PMpants.toml) we can choose the ruff modes we want to use in our project. I think this is what @ancient-vegetable-10556 suggested as well in the end.
The ruff modes could default to only lint when introduced to not change the behaviour for those already using the ruff backend, while having the option for all to opt in to the new modes of ruff as they please.curved-television-6568
11/10/2023, 6:16 PMbetter-van-82973
11/10/2023, 6:17 PMcurved-television-6568
11/10/2023, 6:22 PMbetter-van-82973
11/10/2023, 6:24 PMdef rules():
return [
*collect_rules(),
*RuffFixRequest.rules(),
*RuffLintRequest.rules(),
*RuffFormatRequest.rules(),
*pex.rules(),
]
but it doesn’t seem like there’s a way to selectively disable rules or targets based on the subsystem options?better-van-82973
11/10/2023, 6:25 PM@rule(desc="Format with ruff", level=LogLevel.DEBUG)
async def ruff_fmt(request: RuffFormatRequest.Batch, ruff: Ruff) -> FmtResult:
if RuffMode.FORMAT in ruff.ruff_modes:
result = await Get(
FallibleProcessResult, _RunRuffRequest(snapshot=request.snapshot, mode=RuffMode.FORMAT)
)
return await FmtResult.create(request, result)
else:
# What goes here?curved-television-6568
11/10/2023, 6:47 PMonly options, such as pants fix --only=ruff would run only the ruff fixer... so what I think we'd like to have is the opposite, so we have skip on the tool level, but not skip on the goal level which could look like pants fix --skip=ruff to run all fixers, except ruff.curved-television-6568
11/10/2023, 6:47 PMcurved-television-6568
11/10/2023, 6:49 PMcurved-television-6568
11/10/2023, 6:49 PMbetter-van-82973
11/10/2023, 6:51 PMcurved-television-6568
11/10/2023, 6:52 PMcurved-television-6568
11/10/2023, 6:53 PMskip option on the goal level, it's still doable using the only option but more awkward as you'd have to list all your tools except ruff.bitter-ability-32190
11/13/2023, 6:38 PMbetter-van-82973
11/13/2023, 6:39 PM--only option with pants fmtbitter-ability-32190
11/13/2023, 6:39 PMbitter-ability-32190
11/13/2023, 6:40 PMruff isn't the first one to have this issue either, IIRC. So perhaps at some point we take this to the next level 🙂curved-television-6568
11/13/2023, 7:02 PMskip as complementary to only for the goals…square-psychiatrist-19087
12/27/2023, 8:50 PMpants fix :: and it still formats code with ruff. I've set [fmt].only and it is not respected by pants fix ::bitter-ability-32190
12/27/2023, 8:52 PMpants --skip-ruff fix :: if you want to run all fixers except for ruffsquare-psychiatrist-19087
12/27/2023, 8:54 PMsquare-psychiatrist-19087
12/27/2023, 8:55 PMruff check . --fix
and not
ruff formatsquare-psychiatrist-19087
12/27/2023, 8:55 PMsquare-psychiatrist-19087
12/27/2023, 8:56 PMpants fix to respect [fmt].only and only run ruff check . --fix, but it doesn't workbitter-ability-32190
12/27/2023, 8:58 PMbitter-ability-32190
12/27/2023, 8:58 PM--fixbitter-ability-32190
12/27/2023, 8:59 PMruff is implemented as a fixer, and not a formatter, so it actually shouldn't be running during fmtsquare-psychiatrist-19087
12/27/2023, 9:00 PMsquare-psychiatrist-19087
12/27/2023, 9:01 PMsquare-psychiatrist-19087
12/27/2023, 9:02 PMbitter-ability-32190
12/27/2023, 9:04 PMbitter-ability-32190
12/27/2023, 9:04 PMbetter-van-82973
12/27/2023, 9:06 PMsquare-psychiatrist-19087
12/27/2023, 9:11 PMbetter-van-82973
12/27/2023, 9:12 PMruff check --fix . instead of ruff check . --fix
Lemme try this on my own repo and see if I can trace it downbetter-van-82973
12/27/2023, 9:16 PMskip_formatters flag? https://www.pantsbuild.org/docs/reference-fix#skip_formatterssquare-psychiatrist-19087
12/27/2023, 9:17 PM[fmt].only actually works, it only runs black, but for some reason black now ignores # fmt: on comments in our repo. Not sure why thoughsquare-psychiatrist-19087
12/27/2023, 9:18 PM# fmt: on but then I actually checked the logs and it didn't run
+ black made changes.
✓ isort made no changes.
+ ruff made changes.
✓ ruff --fix made no changes.
✓ shfmt made no changes.better-van-82973
12/27/2023, 9:19 PM16:13:42.75 [INFO] Completed: Format with shfmt - shfmt made no changes.
16:13:42.76 [INFO] Completed: Fix with Autoflake - autoflake made no changes.
16:13:42.76 [INFO] Completed: Fix with Autoflake - autoflake made no changes.
16:13:42.81 [INFO] Completed: Fix with ruff - ruff --fix made no changes.
16:13:42.81 [INFO] Completed: Fix with ruff - ruff --fix made no changes.
16:13:42.82 [INFO] Completed: Format with ruff - ruff made no changes.
16:13:42.82 [INFO] Completed: Format with ruff - ruff made no changes.square-psychiatrist-19087
12/27/2023, 9:20 PM$ pants fix ::
✓ ruff --fix made no changes.square-psychiatrist-19087
12/27/2023, 9:20 PM✓ black made no changes.
✓ isort made no changes.
✓ shfmt made no changes.
here is pants fmt ::square-psychiatrist-19087
12/27/2023, 9:21 PMsquare-psychiatrist-19087
12/27/2023, 9:21 PM+ black made changes.
✓ isort made no changes.
+ ruff made changes.
✓ ruff --fix made no changes.
✓ shfmt made no changes.square-psychiatrist-19087
12/27/2023, 9:21 PMsquare-psychiatrist-19087
12/27/2023, 9:21 PM[fmt]
only=['black', 'isort', 'shfmt']better-van-82973
12/27/2023, 9:22 PMruff --fix also ran that second time, I am guessing the command was pants fix ::?square-psychiatrist-19087
12/27/2023, 9:22 PMsquare-psychiatrist-19087
12/27/2023, 9:23 PMpants fix :: doesn't respect [fmt].only when running formatters and that's weirdbetter-van-82973
12/27/2023, 9:25 PMskip_formatters sufficiently work around the issue?square-psychiatrist-19087
12/27/2023, 9:29 PMpants fix fmt :: works with skip_formatterssquare-psychiatrist-19087
12/27/2023, 9:30 PMbetter-van-82973
12/27/2023, 9:31 PMfunction pants_check_all() {
pants fix lint check test ::
}
alias pca=pants_check_allsquare-psychiatrist-19087
12/27/2023, 9:43 PMsquare-psychiatrist-19087
12/27/2023, 10:45 PM✓ black made no changes.
✓ isort made no changes.
✓ ruff --fix made no changes.
✓ shfmt made no changes.
it includes ruff --fix and doesn't include ruff format
wdyt?curved-television-6568
12/28/2023, 5:35 PMcli.alias option for pants. ;)square-psychiatrist-19087
12/31/2023, 7:18 PM