Skip to main content

· One min read
Gregory Borodin

A frequently asked question on Pants Slack is how to set a version - such as for a docker image, helm chart or Python distribution - based on git state.

Pants does have various solutions for this, but they tend to be too complicated, or too limited:

It turns out there is a hack that elegantly solves this problem. To make it work we need one more pants feature hidden in the docs — the .pants.bootstrap file. It makes it possible to automatically set the VERSION env var right before pants starts:

.pants.bootstrap
#!/bin/sh

VERSION="${VERSION:-$(git describe --tags --dirty --match "[0-9\.]*" || echo 0.0.1)}"
export VERSION

Now we can use the env var everywhere!

To set docker_image tag:

docker_image(
name="image",
image_tags=[env("VERSION")],
)

To pass docker_image build arg:

docker_image(
name="image",
extra_build_args=["VERSION=" + env("VERSION")],
)

To set python_distribution version:

python_distribution(
name="mydist",
provides=python_artifact(
name="mydist",
version=env("VERSION"),
),
)

To set helm_chart version:

helm_chart(
version=env("VERSION"),
)

· 3 min read
Joshua Cannon

Make builds more reliable and save time doing so. The upcoming Pants 2.16 introduces a couple of exciting changes to make Pants safer, faster, and more user-friendly. Here we preview a pair of changes which increase hermeticity.

· 7 min read
Christopher Neugebauer

"Blue Bill Duck" by Richard Ashurst licensed under CC BY 2.0

The 2.15 series represents the biggest change to Pants since version 2.0, and we're excited to share how it can let you complete more workflows, more easily, in more places. Including cross-platform builds, containerized builds with Docker, and easier configuration for local builds…

· 4 min read
Benjy Weinberger

Image by NTNU, Faculty of Natural Sciences (license)

Pants balances release velocity and end-user stability via judicious use of deprecation cycles. Experimental backends are a way to get quick feedback on new functionality, before "graduating" it to the formal deprecation policy. Experimental features are still well-supported, and not to be feared!

· 10 min read
Benjy Weinberger

Unlike earlier build systems, Pants v2 automatically infers your code's internal and external dependencies. And it does this at the file level, so that you get optimal invalidation, caching, and concurrency performance without having to manually create and maintain mountains of BUILD file metadata.

· 6 min read
Stu Hood

Highlights include: less boilerplate via hierarchical defaults for target field values, better Golang monorepo support, with multiple go.mods, do more of your workflows in Pants with the experimental deploy goal (with initial support for Helm), and much more…

· 5 min read
Benjy Weinberger

GraphMyRepo.com in action, graphing the dependencies and code structure of pantsbuild/pants. Source: Toolchain.com

To make it easier to understand the value and power of dependency inference, Toolchain (the lead sponsor of Pants) has built a new site: Graph My Repo. As its name suggests, Graph My Repo shows you an interactive graph of a public GitHub repo of your choice…

· 6 min read
Christopher Neugebauer

We're pleased to announce Pants 2.13.0. Highlights include better command line arguments for file sets, improved JVM support, easier access to parallel execution in CI, and lower barriers to adoption for Python projects that currently use existing distribution and build tools.

· 8 min read
Joshua Cannon

The Python and Docker logos, with a plus sign between them

Pants can build a PEX file, an executable zip file containing your Python code and all transitive dependencies. Deploying your application is as simple as copying the file. This post elaborates on how to get best performance out of the powerful combination of Pants+PEX+Docker.

· 8 min read
Benjy Weinberger

Image by Markus Spiske / CC0 1.0

Working effectively in a monorepo requires appropriate tooling. While Pants can be a really useful system in repos of all sizes and architectures, it has some features that make it particularly appealing in a monorepo setting…

· 5 min read

Pants 2.6 can now understand Poetry's pyproject.toml configuration for third-party dependency management, addressing one of our most requested features in the last year!

Pants Contributor Liam Wilson delves into this new feature as well as his experiences developing the macro as a Toolchain intern.

· 9 min read
Benjy Weinberger

There are so many tools in the Python development ecosystem. Installing, configuring and orchestrating them—all while not re-executing work unnecessarily—is a hard problem, especially as your codebase grows.

Fortunately, there is now a tailor-made (pun intended) solution: Pants v2!