Common subsystem tasks
Common tasks for Subsystems
Skipping individual targets
Many subsystems allow skipping specific targets. For example, you might have Python files that you want to not typecheck with mypy. In Pants, this is achieved with a skip_*
field on the target. This is simple to implement.
- Create a field for skipping your tool
from pants.engine.target import BoolField
class SkipFortranLintField(BoolField):
alias = "skip_fortran_lint"
default = False
help = "If true, don't run fortran-lint on this target's code."
- Register this field on the appropriate targets.
def rules():
return [
FortranSourceTarget.register_plugin_field(SkipFortranLintField),
]
- Add this field as part of your subsystems
opt_out
method:
from dataclasses import dataclass
from pants.engine.target import FieldSet, Target
@dataclass
class FortranLintFieldSet(FieldSet):
required_fields = (FortranSourceField,)
source: FortranSourceField
@classmethod
def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipFortranLintField).value
Making subsystems exportable with their default lockfile
Support depends on language backend of the subsystem
Only some language backends support pants export
. These include the Python and JVM backends. Only tools which are themselves written to use a backend with this feature can be exported. For example, a Python-based tool which operates on a different language is exportable.
-
Make the subsystem a subclass of
ExportableTool
Language backends may have done this in their Tool base class.For example, the Python backend with
PythonToolRequirementsBase
and JVM withJvmToolBase
are already subclasses.from pants.backend.python.subsystems.python_tool_base import PythonToolBase
from pants.core.goals.resolves import ExportableTool
class FortranLint(PythonToolBase, ExportableTool):
... -
Register your class with a
UnionRule
withExportableTool
def rules():
return [
UnionRule(ExportableTool, FortranLint)
]