Skip to main content

pants-plugin-developer-utils

Utilities for writing and testing Pantsbuild plugins: type aliases for the register.py hooks, and pytest fixtures around pants.testutil.rule_runner.RuleRunner.

Installation

The package is on PyPI.

pip install pants-plugin-developer-utils            # type aliases only
pip install "pants-plugin-developer-utils[testing]" # plus the pytest fixtures

In a Pants repo, add the requirement to the resolve your plugin code and tests use. The testing extra also needs pantsbuild.pants.testutil at the same version as the Pants you test against. It is not a declared dependency, because declaring it would pin a Pants version.

Pants loads plugins into its own interpreter, so the package requires the Python version Pants runs on.

Type aliases

Alias Expands to Use as the return type of
CollectedRules Iterable[Rule | UnionRule] rules()
CollectedTargetTypes Iterable[type[Target]] target_types()
# your plugin's `register.py`
from pants_plugin_developer_utils import CollectedRules, CollectedTargetTypes

from your_plugin.module import rules as your_rules
from your_plugin.target_types import YourCustomTarget


def rules() -> CollectedRules:
    return (*your_rules(),)


def target_types() -> CollectedTargetTypes:
    return (YourCustomTarget,)

The aliases are only needed for type checking. To keep your published plugin free of a runtime dependency on this package, import them under TYPE_CHECKING:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from pants_plugin_developer_utils import CollectedRules

Testing utilities

pants_plugin_developer_utils.testing_utils provides:

  • rule_runner_factory: a function-scoped fixture returning a factory that builds a RuleRunner from rules plus any optional RuleRunner keyword arguments.
  • RuleRunnerFactory: the type of that factory, for annotating fixtures that take it.
  • RuleRunnerOptionalKwargs: a TypedDict of the optional RuleRunner constructor arguments.
  • RuleRunnerCollectedRules: CollectedRules widened to accept QueryRule.
# conftest.py
import pytest
from pants.core.goals.package import BuiltPackage
from pants.core.target_types import FileTarget
from pants.testutil.rule_runner import QueryRule, RuleRunner

from pants_plugin_developer_utils.testing_utils import RuleRunnerFactory
from your_plugin import rules as your_rules
from your_plugin.goals.package import YourFieldSet


@pytest.fixture
def your_rule_runner(rule_runner_factory: RuleRunnerFactory) -> RuleRunner:
    return rule_runner_factory(
        rules=[*your_rules(), QueryRule(BuiltPackage, [YourFieldSet])],
        target_types=[FileTarget],
    )

The fixtures register through a pytest11 entry point, so they are available as soon as the wheel is installed. When consuming this package as first-party source instead, import the fixture into a conftest.py:

from pants_plugin_developer_utils.testing_utils import rule_runner_factory  # noqa: F401

Supported versions

Package Pants Python
0.x 2.33 3.14

Releases

Wheels are published to PyPI. Release notes live in the changelog and on the GitHub releases page.

Contributing, Bug Reports and Feature Requests

This package lives in the pants-plugin-depot repo. See its CONTRIBUTING.md, or open an issue.

Metadata

Release files for pants-plugin-developer-utils 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pants-plugin-developer-utils 0.1.0
File Interpreter ABI Platform
pants_plugin_developer_utils-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / pants_plugin_developer_utils-0.1.0-py3-none-any.whl

Download URL pants_plugin_developer_utils-0.1.0-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e5fe9d1f0a89f1f0653fe45ed139c3fdd352e0acb5a9730537cf13041671d28
BLAKE2b-256 checksum
How to use checksums
ab2dc6d789517243af10c3efa6cbb04875af9707ccb7e277a4921b04b2da0996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page