Skip to content

Commit 1445cca

Browse files
authored
chore: demonstrate py_binary stamping (#532)
Came up from a customer question. ---
1 parent 6ad4667 commit 1445cca

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ bazel_dep(name = "bazel_skylib", version = "1.4.2")
1717
bazel_dep(name = "rules_python", version = "0.29.0")
1818
bazel_dep(name = "platforms", version = "0.0.7")
1919

20+
bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains")
21+
bazel_lib.expand_template()
22+
2023
# Custom python version for testing only
2124
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
2225
python.toolchain(

WORKSPACE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ py_repositories()
4242

4343
############################################
4444
# Aspect bazel-lib
45-
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")
45+
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains", "register_expand_template_toolchains")
4646

4747
register_coreutils_toolchains()
4848

49+
register_expand_template_toolchains()
50+
4951
load("@musl_toolchains//:repositories.bzl", "load_musl_toolchains")
5052

5153
load_musl_toolchains(extra_target_compatible_with = ["@//tools/linkers:musl"])

examples/py_binary/BUILD.bazel

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
12
load("//py:defs.bzl", "py_binary")
23

4+
expand_template(
5+
name = "stamped",
6+
stamp_substitutions = {
7+
"<BUILD_TIMESTAMP>": "{{BUILD_TIMESTAMP}}",
8+
},
9+
template = "say.py",
10+
)
11+
312
py_binary(
413
name = "py_binary",
5-
srcs = ["say.py"],
14+
srcs = [":stamped"],
615
deps = [
716
"@pypi_cowsay//:pkg",
817
],

examples/py_binary/say.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import cowsay
22

3-
cowsay.cow('hello py_binary!')
3+
cowsay.cow('hello py_binary! (built at <BUILD_TIMESTAMP>)')

0 commit comments

Comments
 (0)