Skip to content

Commit

Permalink
re-export PyInfo
Browse files Browse the repository at this point in the history
This allows downstream rules to extract the `PyInfo` from the `py_unzip`.
  • Loading branch information
jacobbogdanov committed Aug 14, 2023
1 parent edc6293 commit a1bf833
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/py_unzip/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,19 @@ def _py_unzip_impl(ctx):
)

default_info = _py_binary_shim(ctx)
py_info = _py_info(ctx)

return [
default_info,
py_info,
]

def _py_runtime(ctx):
return ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime

def _py_info(ctx):
return ctx.attr.src[PyInfo]

def _generate_main(ctx):
py_runtime = _py_runtime(ctx)
main_file = ctx.actions.declare_file(ctx.label.name + ".__main__.py")
Expand All @@ -120,7 +125,7 @@ def _generate_main(ctx):
template = ctx.file._main_template,
output = main_file,
substitutions = {
"%imports%": ":".join(ctx.attr.src[PyInfo].imports.to_list()),
"%imports%": ":".join(_py_info(ctx).imports.to_list()),
"%main%": ctx.workspace_name + "/" + ctx.file.main.path,
"%python_binary%": py_runtime.interpreter_path,
"%shebang%": py_runtime.stub_shebang,
Expand Down Expand Up @@ -184,6 +189,10 @@ _py_unzip = rule(
outputs = {
"tar": "%{name}.tar",
},
provides = [
PyInfo, # re-export the PyInfo from the wrapped py_binary.
DefaultInfo,
],
)

def _package_dir(libdir, app_name):
Expand Down

0 comments on commit a1bf833

Please sign in to comment.