pants
Build, test, and manage software projects
TLDR
List all targets
Run all tests
Fix, format, and lint only uncommitted files
Typecheck only uncommitted files and their dependents
Create a distributable package for the specified target
Auto-generate BUILD file targets for new source files
Display help
SYNOPSIS
pants [global-options] command [command-options] [targets...]
Pants commands operate on one or more targets, which represent code units (e.g., a Python module, a Java library). Global options affect the overall behavior of the Pants execution, while command-specific options fine-tune the selected operation.
PARAMETERS
command
The specific operation to perform, such as test, lint, run, or build. Each command has its own set of sub-options.
targets...
One or more addresses specifying the code units or targets that the command should operate on. Examples include `path/to/dir:target_name` or `path/to/dir` for all targets in that directory.
--help
Displays help information for the Pants command overall, or for a specific command when placed after it (e.g., `pants test --help`).
test
Runs tests for the specified targets, leveraging Pants's caching and concurrency for speed.
lint
Executes configured linters (e.g., Flake8, ESLint) against the specified targets to enforce code style and quality.
fmt
Automatically formats code for the specified targets using integrated formatters (e.g., Black, Prettier).
run
Executes a runnable target (e.g., a Python script or a Java main class) directly through Pants.
build
Builds and compiles the specified targets into an executable or deployable artifact within the Pants cache.
package
Creates distributable artifacts (e.g., Python wheels, JAR files, Go binaries) from the specified targets, making them available outside the Pants workspace.
DESCRIPTION
Pants is a high-performance, open-source build system designed to manage large, complex software projects, particularly within monorepos. It excels at building, testing, linting, and packaging code written in various languages like Python, Java, Scala, Go, and more.
It achieves speed through aggressive caching, incremental builds, and concurrent execution. By understanding a project's dependency graph, Pants can precisely determine what needs to be rebuilt or retested, avoiding redundant work. This makes it highly efficient for developer workflows, as changes to one part of a monorepo only trigger rebuilds for affected components.
Key features include flexible target definitions, remote execution capabilities, and a plugin-based architecture for extensibility. It aims to provide a consistent and predictable build experience across large teams and diverse technology stacks, making it a powerful tool for modern software development.
CAVEATS
Pants is not a pre-installed Linux utility but a build system requiring installation, typically via pip. Its usage is primarily within software development environments, especially for teams managing large monorepos. It has a learning curve due to its advanced features and configuration requirements (e.g., defining `BUILD` files and `pants.toml`).
BUILD FILES AND TARGETS
Pants defines buildable units and their dependencies using `BUILD` files (similar to Bazel's `BUILD` files) which are typically located alongside source code. These files specify targets, such as `python_library`, `java_binary`, or `go_test`, and their interdependencies, forming the foundation of the build graph.
CONFIGURATION WITH PANTS.TOML
Global and project-specific configurations for Pants are managed in a `pants.toml` file, usually located at the root of the workspace. This file allows users to configure plugins, set tool versions, define global options, and customize various aspects of the build process.
HISTORY
Pants originated at Twitter around 2011 as an internal build system to address the challenges of managing their rapidly growing monorepo and polyglot codebase. It was subsequently open-sourced in 2013, allowing other organizations facing similar scaling issues to leverage its capabilities. The project has undergone significant evolution, with Pants v2 representing a substantial rewrite focusing on performance, extensibility, and user experience, enabling it to support a wider range of programming languages and advanced build scenarios.