# Using a provider from a custom rule
#
# TODO:
# How to introspect the available providers from the target (you just have to know...)?
# How to use Make variables from the target?
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)
foo = rule(
implementation = _foo_impl,
attrs = {
"version": attr.label(
default = "@rules_python_extras//python:current_py_version", # <-- provider
),
},
) |