Add --black-enable
option to turn Black on and off
#8672
Closed
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.
NOTE: this is made on top of #8671. See Eric-Arellano/pants@refactor-black...Eric-Arellano:black-enable for the difference between the two.
Problem
We need a mechanism for users to say that they want to use a tool like Black or not. Not every codebase will want to use the tool, such as Pants not yet using it, but users should still be able to do
./pants fmt-v2
and./pants lint-v2
.We currently do this in V1 through the
--skip
option, which is applied recursively so allows for--fmt-skip
,--fmt-black-skip
,--fmt-isort-skip
, etc. This will not work with V2, however, because we cannot have options on specific "tasks" anymore. Options must either reside at the Goal level or in a subsystem.Solution
Define the skip/enable mechanism directly on the tool itself, i.e.
--no-black-enable
and--black-enable
.This has a major benefit that in V2 we are setting up tools to provide both
fmt
andlint
implementations, where possible. This means that Black will run under both./pants fmt
and./pants lint
. Were we to keep the V1--skip
implementation, we would need to configure:This rarely seems to be desirable. Presumably, if one is autoformatting with Black, they would also want to enforce that this is actually happening. (Note that discussion is irrelevant for linters like
Pylint
).Instead, this approach looks like:
[black] enable: True
Result
We can now write new rules for
fmt-v2
andlint-v2
, like implementing isort, without having those commands trigger Black when Black is not used by the codebase.