<#18528 Expose Pants version to BUILD files> Issue...
# github-notifications
c
#18528 Expose Pants version to BUILD files Issue created by tgolsson It'd be useful to expose the current pants version to build scripts. There's two main reasons for this: • it is generally useful to put tool versions into built artifacts, just like git versions; environment information, and so on. • it would be useful for third-party plugin developers (and consumers) to handle plugin changes, to gracefully test across multiple pants versions even when those versions might not work everywhere As a topical example; I'm adding support to my OCI builder backend to support empty base images. I want this to use a real, explicit, target - but I don't want to have a million of them, as it'll always be the same image. Synthetic targets solve this by allowing me to generate this target. However; synthetic targets are a 2.15 feature and my minimum supported is still 2.14 (like Pants itself). Thus, to provide examples of usage (which also becomes e2e tests!) I ended up wanting to write something like this:
Copy code
empty_base = "//:empty"  # see [oci].empty_image_target

# using pants 2.15+ there's a built-in for empty bases, but before that we need to declare an empty image to use:
if not pants_at_least("2.15.0.dev0"):
    oci_image_empty(
        name="empty",
    )
    empty_base = ":empty"

oci_image_build(
    name="with_empty_base",
    base=[empty_base],
    packages=[":example"],
    tag="latest",
)
Doing this right now requires some hacking to read and compare the version, since imports are forbidden:
Copy code
def pants_at_least(version: str) -> bool:
    pants = __import__("pants")

    return pants.version.PANTS_SEMVER >= pants.version.Version(version)
Describe the solution you'd like If the (stringified?) value of
PANTS_SEMVER
was exposed to the BUILD files, the first kind of use-cases would be possible - and the second would be possible for someone who cares enough to do it. I don't think this necessarily should be encouraged and thus there's no "easy" comparison, but it's a nice escape hatch for those who find the need or run matrix testing over pants itself and want to early adopt coming features. Additional context https://pantsbuild.slack.com/archives/C046T6T9U/p1679234208316439 I'm willing to also do the work required here if we can agree that it should be done (and how ;-)) pantsbuild/pants