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

fix(py_wheel.publish): allow twine tags and args #1271

Merged
merged 2 commits into from
Jun 15, 2023
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: 2 additions & 1 deletion docs/packaging.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions python/packaging.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _py_wheel_dist_impl(ctx):
use_default_shell_env = True,
)
return [
DefaultInfo(files = depset([dir])),
DefaultInfo(files = depset([dir]), runfiles = ctx.runfiles([dir])),
]

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

def py_wheel(name, twine = None, **kwargs):
def py_wheel(name, twine = None, publish_args = [], **kwargs):
"""Builds a Python Wheel.

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

# TODO: use py_binary from //python:defs.bzl after our stardoc setup is less brittle
# buildifier: disable=native-py
native.py_binary(
name = "{}.publish".format(name),
srcs = [twine_main],
args = [
"upload",
"$(rootpath :{})/*".format(_dist_target),
],
args = twine_args,
data = [_dist_target],
imports = ["."],
main = twine_main,
deps = [twine],
visibility = kwargs.get("visibility"),
**copy_propagating_kwargs(kwargs)
)

py_wheel_rule = _py_wheel