Providers
[ 1 Using a Custom Provider ]
Using a Custom Provider
# Using a provider from a custom rule
#
# TODO:
# How to introspect the available providers from the target (you just have to know...)?
def _foo_impl(ctx):
if SemanticVersionInfo in ctx.attr.version:
print("Version: ", ctx.attr.version[SemanticVersionInfo].version) # <-- fetching the provider structure
print("Dir: ", dir(ctx.attr.version)) # <-- this only shows 'target' fields (mostly useless)
if platform_common.TemplateVariableInfo in ctx.attr.version:
for varname, varsub in ctx.attr.version[platform_common.TemplateVariableInfo].variables.items():
print("Varname: ", varname)
print("Varsub:", varsub)
foo = rule(
implementation = _foo_impl,
attrs = {
"version": attr.label(
default = "@rules_python_extras//python:current_py_version", # <-- provider
),
},
) |