Plugin upgrade guide
How to adjust for changes made to the Plugin API.
2.11
See https://github.com/pantsbuild/pants/blob/main/src/python/pants/notes/2.11.x.md for the changelog.
Deprecated Subsystem.register_options()
Pants 2.11 added "concrete" option types which when used as class attributes of your subsystem. These are more declarative, simplify accessing options, and work with MyPy!
Before:
class MySubsystem(Subsystem):
options_scope = "example"
help = "..."
@classmethod
def register_options(cls, register):
super().register_options(register)
register(
"--my-opt",
type=bool,
default=True,
help="...",
)
Now:
class MySubsystem(Subsystem):
options_scope = "example"
help = "..."
my_opt = BoolOption(
"--my-opt",
default=True,
help="...",
)
To access an option in rules, simply use my_subsystem.my_opt
rather than my_subsystem.options.my_opt
.
See Options and subsystems for more information, including the available types.
Moved BinaryPathRequest
to pants.core.util_rules.system_binaries
The new module pants.core.util_rules.system_binaries
centralizes all discovery of existing binaries on a user's machines.
The functionality is the same, you only need to change your imports for types like BinaryPathRequest
to pants.core.util_rules.system_binaries
rather than pants.engine.process
.
Deprecated not implementing TargetGenerator
in GenerateTargetsRequest
implementors
See https://github.com/pantsbuild/pants/pull/14962 for an explanation and some examples of how to fix.
Replaced GoalSubsystem.required_union_implementations
with GoalSubsystem.activated()
See https://github.com/pantsbuild/pants/pull/14313 for an explanation and some examples of how to fix.
2.10
See https://github.com/pantsbuild/pants/blob/main/src/python/pants/notes/2.10.x.md for the changelog.
Rename LintRequest
to LintTargetsRequest
Pants 2.10 added a new LintFilesRequest
, which allows you to run linters on code without any owning targets! https://github.com/pantsbuild/pants/pull/14102
To improve clarity, we renamed LintRequest
to LintTargetsRequest
.
FmtRequest
, CheckRequest
, and LintTargetsRequest
must set name
You must set the class property name
on these three types.
Before:
class MyPyRequest(CheckRequest):
field_set_type = MyPyFieldSet
After:
class MyPyRequest(CheckRequest):
field_set_type = MyPyFieldSet
name = "mypy"
This change is what allowed us to add the lint --only=flake8
feature.
For DRY, it is a good idea to change the formatter_name
, linter_name
, and checker_name
in FmtResult
, LintResults
, and CheckResults
, respectively, to use request.name
rather than hardcoding the string again. See https://github.com/pantsbuild/pants/pull/14304 for examples.
Removed LanguageFmtTargets
for fmt
When setting up a new language to be formatted, you used to have to copy and paste a lot of boilerplate like ShellFmtTargets
. That's been fixed, thanks to https://github.com/pantsbuild/pants/pull/14166.
To fix your code:
- If you defined any new languages to be formatted, delete the copy-and-pasted
LanguageFmtTargets
code. - For every formatter, change the
UnionRule
to beUnionRule(FmtRequest, BlackRequest)
, rather thanUnionRule(PythonFmtRequest, BlackRequest)
, for example.
ReplImplementation
now passes root targets, not transitive closure
We realized that it's useful to let REPL rules know what was specified vs. what is a transitive dependency: https://github.com/pantsbuild/pants/pull/14323.
To adapt to this, you will want to use transitive_targets = await Get(TransitiveTargets, TransitiveTargetsRequest(request.addresses)
, then operate on transitive_targets.closure
.
Removed PexFromTargetsRequest.additional_requirements
Let us know if you were using this, and we can figure out how to add it back: https://github.com/pantsbuild/pants/pull/14350.
Removed PexFromTargetsRequest(direct_deps_only: bool)
Let us know if you were using this, and we can figure out how to add it back: https://github.com/pantsbuild/pants/pull/14291.
Renamed GenerateToolLockfileSentinel.options_scope
to resolve_name
See https://github.com/pantsbuild/pants/pull/14231 for more info.