AgentSkillsCN

Pants Setup

在仓库中设置并管理 Pants 构建系统——添加基础插件、发现软件包、配置 pants.toml、搜索插件,以及执行日常维护任务。

SKILL.md
--- frontmatter
description: Setup and manage Pants build system in repositories - add baseline plugins, discover packages, configure pants.toml, search for plugins, and housekeeping tasks
user_invocable: true
triggers:
  - "setup pants"
  - "add pants"
  - "install pants plugin"
  - "pants baseline"
  - "configure pants"
  - "pants.toml"
  - "add python baseline"
  - "remove pants"
  - "pants packages"
  - "pants housekeeping"
  - "search pants plugins"
  - "find pants plugins"
  - "list pants plugins"

Pants Setup & Housekeeping

You help users set up and manage the Pants build system in their repositories. This includes adding plugins, configuring pants.toml, discovering available packages, and general housekeeping tasks.

Capabilities

1. Add Python Baseline Plugin

Add the opinionated Python code quality baseline to a repo:

toml
# In pants.toml
[GLOBAL]
backend_packages = [
    "pants.backend.python",
    "pants_baseline",
]
plugins = ["jaymd96-pants-baseline==0.1.0"]

[python-baseline]
python_version = "3.13"
line_length = 120
coverage_threshold = 80

2. Search for Available Plugins

Search GitHub and PyPI for jaymd96 Pants plugins:

bash
# Search GitHub repos with pants-plugin label
gh repo list jaymd96 --topic pants-plugin --json name,description

# Check PyPI for a specific plugin
curl -s "https://pypi.org/pypi/jaymd96-pants-baseline/json" | jq '.info.version'

# List all installed pants plugins
pip list | grep jaymd96-pants

3. Discover Built-in Backend Packages

Help users discover Pants backend packages and third-party plugins:

Built-in Backend Packages:

PackagePurpose
pants.backend.pythonPython support
pants.backend.python.lint.ruffRuff linting
pants.backend.python.typecheck.mypyMyPy type checking
pants.backend.dockerDocker support
pants.backend.shellShell script support
pants.backend.experimental.pythonExperimental Python features

4. Remove/Disable Packages

Help users clean up unused packages from pants.toml.

5. General Housekeeping

  • Validate pants.toml configuration
  • Check for outdated plugins
  • Optimize backend package selection
  • Set up recommended defaults

Workflow

When a user wants to set up or manage Pants:

Step 1: Assess Current State

Check if Pants is already set up in the repo:

bash
# Check for pants.toml
ls pants.toml 2>/dev/null && echo "Pants is configured" || echo "No pants.toml found"

# Check Pants version if installed
pants --version 2>/dev/null || echo "Pants not installed"

Step 2: Determine User Intent

Ask what they want to do:

  • New Setup: Create pants.toml from scratch
  • Add Plugin: Add a specific plugin to existing setup
  • Remove Plugin: Remove unused plugins
  • Discover: Show available packages
  • Validate: Check current configuration

Step 3: Execute

Based on intent, perform the appropriate action.


Installing Pants (Bootstrap Script)

The recommended way to install Pants is using the bootstrap script. This ensures consistent Pants versions across all developers and CI environments.

Download and Setup

bash
# Download the official Pants launcher
curl -fsSL https://static.pantsbuild.org/setup/pants -o pants
chmod +x pants

How It Works

The ./pants script is a small launcher that:

  1. Reads pants_version from pants.toml
  2. Downloads that specific Pants version if not cached
  3. Runs the requested Pants command

This means developers don't need to install Pants globally - just run ./pants and it handles everything.

Commit the Script

Always commit the pants script to version control:

bash
git add pants
git commit -m "Add Pants bootstrap script"

Example pants.toml

toml
[GLOBAL]
pants_version = "2.30.1"
backend_packages = [
    "pants.backend.python",
]

[python]
interpreter_constraints = ["CPython>=3.13,<4"]

First Run

bash
# This downloads Pants and shows available goals
./pants goals

# Run a specific goal
./pants lint ::

CI Integration

In CI, just use ./pants directly - no installation step needed:

yaml
# GitHub Actions example
- name: Run tests
  run: ./pants test ::

For more details, see: https://www.pantsbuild.org/stable/docs/getting-started/installing-pants


Adding Python Baseline

When adding the Python baseline plugin:

1. Check Prerequisites

bash
# Ensure pants.toml exists
if [ ! -f pants.toml ]; then
    echo "Creating pants.toml..."
fi

2. Create/Update pants.toml

toml
[GLOBAL]
pants_version = "2.30.1"
backend_packages = [
    "pants.backend.python",
    "pants_baseline",
]
plugins = [
    "jaymd96-pants-baseline==0.1.0",
]

[python]
interpreter_constraints = ["CPython>=3.13,<4"]

# Python Baseline Configuration
[python-baseline]
enabled = true
python_version = "3.13"
line_length = 120
src_roots = ["src"]
test_roots = ["tests"]
coverage_threshold = 80
strict_mode = true

# Ruff Configuration
[ruff]
select = ["E", "F", "I", "B", "UP", "C4", "SIM", "RUF"]
ignore = ["E501"]
quote_style = "double"
fix = true

# ty Configuration (Astral's type checker)
[ty]
strict = true
output_format = "text"

# uv Configuration
[uv]
audit_enabled = true

3. Create BUILD File

python
# BUILD (in project root)
baseline_python_project(
    name="project",
    sources=["src/**/*.py"],
    test_sources=["tests/**/*.py"],
    python_version="3.13",
    line_length=120,
    strict=True,
    coverage_threshold=80,
)

4. Verify Setup

bash
# Test the setup
pants goals
pants baseline-lint ::

Available Backend Packages

Core Python

PackageDescription
pants.backend.pythonCore Python support
pants.backend.python.mixed_interpreter_constraintsMultiple Python versions

Linting & Formatting

PackageDescription
pants.backend.python.lint.ruffRuff linter (recommended)
pants.backend.python.lint.flake8Flake8 linter
pants.backend.python.lint.pylintPylint linter
pants.backend.python.lint.blackBlack formatter
pants.backend.python.lint.isortImport sorter
pants.backend.python.lint.banditSecurity linter

Type Checking

PackageDescription
pants.backend.python.typecheck.mypyMyPy type checker
pants.backend.python.typecheck.pyrightPyright type checker

Testing

PackageDescription
pants.backend.python.pytestpytest (included in core)

Packaging

PackageDescription
pants.backend.python.packaging.pyoxidizerPyOxidizer binaries
pants.backend.experimental.python.packaging.pyoxidizerExperimental PyOxidizer

Other Languages

PackageDescription
pants.backend.dockerDocker support
pants.backend.shellShell scripts
pants.backend.javascriptJavaScript/TypeScript
pants.backend.goGo support
pants.backend.javaJava support
pants.backend.scalaScala support

Third-Party Plugins (jaymd96)

Available Plugins

PluginGitHubPyPIDescription
baselinepants-baselinejaymd96-pants-baselinePython quality baseline (Ruff, ty, uv, pytest)

Searching for Plugins

Search GitHub:

bash
# List all jaymd96 pants plugins
gh repo list jaymd96 --topic pants-plugin --json name,description

# Search with more details
gh repo list jaymd96 --topic pants-plugin --json name,description,url --jq '.[] | "\(.name): \(.description)"'

Search PyPI:

bash
# Check if a plugin exists
curl -s "https://pypi.org/pypi/jaymd96-pants-{name}/json" | jq '.info | {name, version}'

# Check available versions
curl -s "https://pypi.org/pypi/jaymd96-pants-baseline/json" | jq '.releases | keys'

Plugin Naming Conventions

When creating or searching for plugins, follow these conventions:

ComponentConventionExample
GitHub Repopants-{name}pants-baseline
PyPI Packagejaymd96-pants-{name}jaymd96-pants-baseline
Python Packagepants_{name}pants_baseline
GitHub Labelspants-plugin, {name}pants-plugin, baseline

See Naming Conventions for full details.


Removing Packages

To remove a package:

  1. Remove from backend_packages in pants.toml
  2. Remove from plugins if it's a third-party plugin
  3. Remove related configuration sections
  4. Clean up BUILD files that use removed target types

Example - removing Flake8 after switching to Ruff:

toml
# Before
[GLOBAL]
backend_packages = [
    "pants.backend.python",
    "pants.backend.python.lint.flake8",  # REMOVE
    "pants.backend.python.lint.ruff",
]

# After
[GLOBAL]
backend_packages = [
    "pants.backend.python",
    "pants.backend.python.lint.ruff",
]

Validation Checklist

When validating a Pants setup:

  • pants_version is set and recent
  • backend_packages includes all needed backends
  • plugins are versioned (avoid floating versions)
  • interpreter_constraints match project requirements
  • Source roots are correctly configured
  • No duplicate or conflicting backends
bash
# Validate configuration
pants help-all | head -20

# Check for issues
pants lint :: --check

# Verify targets are discovered
pants list ::

Quick Setup Commands

bash
# Initialize new Pants repo
pants # Downloads Pants if not installed

# Show current configuration
pants help-advanced global

# List all available goals
pants goals

# Show backends in use
grep -A 20 "backend_packages" pants.toml

Reference