-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.bzl
More file actions
23 lines (21 loc) · 995 Bytes
/
python.bzl
File metadata and controls
23 lines (21 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
load("@aspect_rules_py//py:defs.bzl", _py_binary = "py_binary")
def py_binary(name, add_completions = True, **kwargs):
"""py_binary wrapper to add bash completion"""
_py_binary(
name = name,
**kwargs
)
if add_completions:
# Follow `click`'s shell completion guide:
# https://click.palletsprojects.com/en/stable/shell-completion/
# Note that Python binaries will want to set
# `entry_point_func(prog_name='{name}')` so click recognizes the
# request for completions in Bazel settings. `{name}` should also
# be the name of the `console_scripts` entry in the wheel.
native.genrule(
name = name + "_completions",
outs = ["{}-completion.bash".format(name)],
cmd = "_{0}_COMPLETE=bash_source $(execpath :{1}) > $(@D)/{2}-completion.bash".format(name.upper(), name, name),
tools = [":{}".format(name)],
visibility = ["//visibility:public"],
)