Skip to content

Commit e223da8

Browse files
authored
Support configuration variables in py_wheel "version" attirbute. (#640)
1 parent 58b38e3 commit e223da8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

docs/packaging.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/packaging.bzl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,18 @@ def _escape_filename_segment(segment):
114114
escaped += "_"
115115
return escaped
116116

117+
def _replace_make_variables(flag, ctx):
118+
"""Replace $(VERSION) etc make variables in flag"""
119+
if "$" in flag:
120+
for varname, varsub in ctx.var.items():
121+
flag = flag.replace("$(%s)" % varname, varsub)
122+
return flag
123+
117124
def _py_wheel_impl(ctx):
125+
version = _replace_make_variables(ctx.attr.version, ctx)
118126
outfile = ctx.actions.declare_file("-".join([
119127
_escape_filename_segment(ctx.attr.distribution),
120-
_escape_filename_segment(ctx.attr.version),
128+
_escape_filename_segment(version),
121129
_escape_filename_segment(ctx.attr.python_tag),
122130
_escape_filename_segment(ctx.attr.abi),
123131
_escape_filename_segment(ctx.attr.platform),
@@ -143,7 +151,7 @@ def _py_wheel_impl(ctx):
143151

144152
args = ctx.actions.args()
145153
args.add("--name", ctx.attr.distribution)
146-
args.add("--version", ctx.attr.version)
154+
args.add("--version", version)
147155
args.add("--python_tag", ctx.attr.python_tag)
148156
args.add("--python_requires", ctx.attr.python_requires)
149157
args.add("--abi", ctx.attr.abi)
@@ -298,7 +306,8 @@ Stamped targets are not rebuilt unless their dependencies change.
298306
mandatory = True,
299307
doc = (
300308
"Version number of the package. Note that this attribute " +
301-
"supports stamp format strings. Eg `1.2.3-{BUILD_TIMESTAMP}`"
309+
"supports stamp format strings (eg. `1.2.3-{BUILD_TIMESTAMP}`) " +
310+
"as well as 'make variables' (e.g. `1.2.3-$(VERSION)`)."
302311
),
303312
),
304313
"_stamp_flag": attr.label(

0 commit comments

Comments
 (0)