ConfiguredTargetNode
ConfiguredTargetNode.attrs_eager
def ConfiguredTargetNode.attrs_eager()
Returns a struct of all the attributes of this target node. The structs fields are the attributes names, and the values are [StarlarkConfiguredAttr
].
If you need to access many or all attrs on the same node, then this is the preferred way. Otherwise,
using attrs_lazy()
would be a better option for only accessing only a few attrs, although this really
depends on what kind of attrs are on the node. Benchmarking performance will give you the best
indication on which method to use.
You should store the result of this function call for further usage in the code rather than calling
attrs_eager()
each time you need to access the attrs.
Right now, it is not recommended to use this method. Instead, use get_attr
and get_attrs
methods.
We will deprecate this method in the future.
Sample usage:
def _impl_attrs_eager(ctx):
node = ctx.cquery().owner("cell//path/to/TARGETS")[0]
attrs = node.attrs_eager() # cache once
ctx.output.print(attrs)
# do more stuff with attrs
ConfiguredTargetNode.attrs_lazy
def ConfiguredTargetNode.attrs_lazy(
) -> bxl.LazyAttrs
Returns a lazy_attrs
object that you can call get()
on that gets an attr one at a time.
If you need to access only few attrs on the same node, then this is the preferred way. Otherwise,
using attrs_eager()
would be a better option for accessing many or all attrs, although this really
depends on what kind of attrs are on the node. Benchmarking performance will give you the best
indication on which method to use.
You should store the result of this function call for further usage in the code rather than calling
attrs_lazy()
each time to get the lazy_attrs
object. Note that if the get()
is None
,
then any methods called on None
will result in an error.
Right now, it is not recommended to use this method. Instead, use get_attr
and get_attrs
methods.
We will deprecate this method in the future.
Sample usage:
def _impl_attrs_lazy(ctx):
node = ctx.cquery().owner("cell//path/to/TARGETS")[0]
attrs = node.attrs_lazy() # cache once
ctx.output.print(attrs.get("some_attributes").value())
ctx.output.print(attrs.get("some_attribute").label)
ConfiguredTargetNode.buildfile_path
ConfiguredTargetNode.buildfile_path: bxl.FileNode
Gets the buildfile path from the configured target node.
Sample usage:
def _impl_label(ctx):
target_node = ctx.cquery().eval("owner('path/to/file')")[0]
ctx.output.print(target_node.buildfile_path)
ConfiguredTargetNode.deps
def ConfiguredTargetNode.deps(
) -> list[bxl.ConfiguredTargetNode]
Gets all deps for this target. The result is a list of ConfiguredTargetNode
.
Sample usage:
def _impl_get_deps(ctx):
target_node = ctx.uquery().eval("//foo:bar")[0]
ctx.output.print(target_node.deps())
ConfiguredTargetNode.get_attr
def ConfiguredTargetNode.get_attr(
key: str,
/,
)
Gets the attribute from the configured target node. If the attribute is unset, returns the default value. If the attribute is not defined by the rule, returns None
. It will not return special attribute (attribute that start with 'buck.' in buck2 cquery -A
command).
Sample usage:
def _impl_attributes(ctx):
target_node = ctx.uquery().eval("//foo:bar")[0]
ctx.output.print(target_node.get_attr('my_attr'))