Pants v2: Fast, consistent builds for Python and more

Welcome to the Pants v2 documentation hub!

Pants v2 is a fast, scalable build system for growing codebases. It's currently focused on Python, with support for other languages coming soon.

Here you'll find guides to help you get started with Pants v2, comprehensive documentation on how to configure, run and customize Pants v2, and information on how to get help from the Pants community.

Get Started

Extending pre-existing targets

Adding new fields to target types.

When to add new fields?

Adding new fields is useful when you are already using a target type, but need to store additional metadata for your plugin.

For example, if you're writing a codegen plugin to convert a protobuf_library into Java source files, you may want to add a jdk_version field to protobuf_library.

If you are instead adding support for a new language, create a new target type.

If you want to reduce boilerplate in BUILD files, such as changing default values, use macros.

How to add new fields

First, define the field. Then, register it by using OriginalTarget.register_plugin_field(CustomField), like this:

from pants.backend.codegen.protobuf.target_types import ProtobufLibrary
from pants.engine.target import BoolField


class ProtobufJdkVersion(IntField):
    """Which JDK protobuf should target."""

    alias = "jdk_version"
    default = 11


def rules():
    return [ProtobufLibrary.register_plugin_field(ProtobufJdkVersion)]

To confirm this worked, run ./pants help protobuf_library, and you should see your new field.

Updated about a month ago


Extending pre-existing targets


Adding new fields to target types.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.