Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
# 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)
    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
        ),
    },
)

...