-
-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Black into a plugin to enable turning it on and off via `backend…
…_plugins` (#8683) ### Problem We need some mechanism to turn off autoformatters and linters in V2 other than the current `--fmt-{isort,scalafmt,etc}-skip`, which doesn't work because that uses a task-specific option system. Ideally, the option will be tool-specific, so you can say something like: ```ini [black] enable: True [mypy] enable: False ``` However, the solution should also be hygienic. If, for example, someone doesn't want to use Black, then we don't want Black's rules to pollute the rule graph. Nor do we want to make rule authors provide a no-op implementation. ### Solution We decided in #8346 to turn each linter into its own plugin, meaning it may be enabled via the `backend_packages` option like this: ```ini [GLOBAL] backend_packages: +[ "pants.backend.python.lint.black", "pants.backend.python.lint.isort", "pants.backend.scala.lint.scalafmt", ] ``` When specified, that plugin will be enabled, meaning that its options may be configured and its rules will be automatically registered against `fmt` and `lint`. ### Result We have a scalable and explicit mechanism for users to enable formatters and linters in a way that also makes it effortless for rule authors to have a way to opt-out of their tool. This only implements Black. In a followup, we will implement isort under the plugin `pants.backend.python.lint.isort`. For now, V1 tasks will keep the same mechanism as before. We could move them towards this new plugin system, but save that for a followup if we choose to make the deprecations necessary to move V1 users towards the new system.
- Loading branch information
1 parent
8ab7cd1
commit 6e22891
Showing
10 changed files
with
67 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_library( | ||
dependencies=[ | ||
'3rdparty/python:dataclasses', | ||
'src/python/pants/backend/python/subsystems', | ||
'src/python/pants/backend/python/rules', | ||
'src/python/pants/backend/python/targets', | ||
'src/python/pants/engine:fs', | ||
'src/python/pants/engine:isolated_process', | ||
'src/python/pants/engine:rules', | ||
'src/python/pants/engine:selectors', | ||
'src/python/pants/option', | ||
'src/python/pants/rules/core', | ||
], | ||
) | ||
|
||
python_tests( | ||
name='tests', | ||
sources=globs('*_test.py', exclude=[globs('*_integration_test.py')]), | ||
dependencies=[ | ||
':black', | ||
], | ||
) | ||
|
||
|
||
python_tests( | ||
name='integration', | ||
sources=globs('*_integration_test.py'), | ||
dependencies=[ | ||
':black', | ||
'src/python/pants/backend/python/subsystems', | ||
'src/python/pants/backend/python/targets', | ||
'src/python/pants/engine:fs', | ||
'src/python/pants/engine:rules', | ||
'src/python/pants/engine:selectors', | ||
'src/python/pants/engine/legacy:structs', | ||
'src/python/pants/rules/core', | ||
'src/python/pants/source', | ||
'src/python/pants/testutil:test_base', | ||
'src/python/pants/testutil/subsystem', | ||
], | ||
tags = {'integration'}, | ||
timeout = 90, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
|
||
from pants.backend.python.lint.black import rules as black_rules | ||
from pants.backend.python.targets import formattable_python_target | ||
|
||
|
||
def rules(): | ||
return ( | ||
*black_rules.rules(), | ||
*formattable_python_target.rules(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters