Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: demonstrate py_binary stamping #532

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "rules_python", version = "0.29.0")
bazel_dep(name = "platforms", version = "0.0.7")

bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains")
bazel_lib.expand_template()

# Custom python version for testing only
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
python.toolchain(
Expand Down
4 changes: 3 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ py_repositories()

############################################
# Aspect bazel-lib
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains", "register_expand_template_toolchains")

register_coreutils_toolchains()

register_expand_template_toolchains()

load("@musl_toolchains//:repositories.bzl", "load_musl_toolchains")

load_musl_toolchains(extra_target_compatible_with = ["@//tools/linkers:musl"])
Expand Down
11 changes: 10 additions & 1 deletion examples/py_binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("//py:defs.bzl", "py_binary")

expand_template(
name = "stamped",
stamp_substitutions = {
"<BUILD_TIMESTAMP>": "{{BUILD_TIMESTAMP}}",
},
template = "say.py",
)

py_binary(
name = "py_binary",
srcs = ["say.py"],
srcs = [":stamped"],
deps = [
"@pypi_cowsay//:pkg",
],
Expand Down
2 changes: 1 addition & 1 deletion examples/py_binary/say.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import cowsay

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