Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e223da8

Browse filesBrowse files
authored
Support configuration variables in py_wheel "version" attirbute. (bazel-contrib#640)
1 parent 58b38e3 commit e223da8
Copy full SHA for e223da8

File tree

Expand file treeCollapse file tree

2 files changed

+13
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-4
lines changed

‎docs/packaging.md

Copy file name to clipboardExpand all lines: docs/packaging.md
+1-1Lines 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

Copy file name to clipboardExpand all lines: python/packaging.bzl
+12-3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.