pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.32k stars 636 forks source link

`pants fix` goal runs formatters, but doesn't respect `[fmt].only` parameter #20342

Open pp-gborodin opened 10 months ago

pp-gborodin commented 10 months ago

Describe the bug Imagine I have black and isort configured, and I set[fmt].only = "black". With this setup I expect pants fix :: to only run black, but this is not the case, it runs both black and isort.

Pants version 2.20.0dev3

OS Ubuntu 22.04

Additional info Looks like the issue is here, the fix rule doesn't respect FmtSubsystem

grihabor commented 10 months ago

I want to explain my motivation here: I tried using new ruff formatter (pants release 2.20.0dev3) along with ruff checker. It uses the same tool_subsystem = Ruff and therefore the same tool_id = "ruff". This makes it impossible to turn off the ruff formatter, but not the ruff checker.

My first idea was to make pants fix respect [fmt].only parameter, this way I could set [fmt].only=['black'] and run pants fix and it will only run ruff check --fix and not ruff format. But now I'm not sure it's a good idea, because [fmt] is dedicated to the fmt goal, it's not clear why fix goal should respect fmt subsystem. The same logic also applies to lint goal, if fix goal respects [fmt] then lint goal should also respect [fmt], right? It all looks weird, so I think the right solution is to change tool_id for ruff:

class RuffFixRequest(FixTargetsRequest):
    tool_id = 'ruff-check'
    ...

class RuffFormatRequest(FmtTargetsRequest):
    tool_id = 'ruff-format'
    ...

This will solve the issue and keep the current lint/format/fix structure.