8000 fix(py_wheel.publish): allow twine tags and args (#1271) · cflewis/rules_python@0cd6c25 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cd6c25

Browse files
alexeaglerickeylev
andauthored
fix(py_wheel.publish): allow twine tags and args (bazel-contrib#1271)
Also fix missing runfiles on the py_wheel.dist target. Fixes bazel-contrib#1130 Fixes bazel-contrib#1270 --------- Co-authored-by: Richard Levasseur <rlevasseur@google.com>
1 parent 1c58124 commit 0cd6c25

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

docs/packaging.md

Lines changed: 2 additions & 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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _py_wheel_dist_impl(ctx):
5050
use_default_shell_env = True,
5151
)
5252
return [
53-
DefaultInfo(files = depset([dir])),
53+
DefaultInfo(files = depset([dir]), runfiles = ctx.runfiles([dir])),
5454
]
5555

5656
py_wheel_dist = rule(
@@ -69,7 +69,7 @@ This also has the advantage that stamping information is included in the wheel's
6969
},
7070
)
7171

72-
def py_wheel(name, twine = None, **kwargs):
72+
def py_wheel(name, twine = None, publish_args = [], **kwargs):
7373
"""Builds a Python Wheel.
7474
7575
Wheels are Python distribution format defined in https://www.python.org/dev/peps/pep-0427/.
@@ -142,6 +142,9 @@ def py_wheel(name, twine = None, **kwargs):
142142
Args:
143143
name: A unique name for this target.
144144
twine: A label of the external location of the py_library target for twine
145+
publish_args: arguments passed to twine, e.g. ["--repository-url", "https://pypi.my.org/simple/"].
146+
These are subject to make var expansion, as with the `args` attribute.
147+
Note that you can also pass additional args to the bazel run command as in the example above.
145148
**kwargs: other named parameters passed to the underlying [py_wheel rule](#py_wheel_rule)
146149
"""
147150
_dist_target = "{}.dist".format(name)
@@ -158,21 +161,22 @@ def py_wheel(name, twine = None, **kwargs):
158161
if not twine.endswith(":pkg"):
159162
fail("twine label should look like @my_twine_repo//:pkg")
160163
twine_main = twine.replace(":pkg", ":rules_python_wheel_entry_point_twine.py")
164+
twine_args = ["upload"]
165+
twine_args.extend(publish_args)
166+
twine_args.append("$(rootpath :{})/*".format(_dist_target))
161167

162168
# TODO: use py_binary from //python:defs.bzl after our stardoc setup is less brittle
163169
# buildifier: disable=native-py
164170
native.py_binary(
165171
name = "{}.publish".format(name),
166172
srcs = [twine_main],
167-
args = [
168-
"upload",
169-
"$(rootpath :{})/*".format(_dist_target),
170-
],
173+
args = twine_args,
171174
data = [_dist_target],
172175
imports = ["."],
173176
main = twine_main,
174177
deps = [twine],
175178
visibility = kwargs.get("visibility"),
179+
**copy_propagating_kwargs(kwargs)
176180
)
177181

178182
py_wheel_rule = _py_wheel

0 commit comments

Comments
 (0)
0