Skip to main content

UnconfiguredTargetNode

Methods for unconfigured target node.

UnconfiguredTargetNode.attrs

UnconfiguredTargetNode.attrs: typing.Any

Gets the coerced attributes from the unconfigured target node. Returns a struct. 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_attributes(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.attrs.my_attr)

UnconfiguredTargetNode.buildfile_path

UnconfiguredTargetNode.buildfile_path: bxl.FileNode

Gets the buildfile path from the unconfigured target node.

Sample usage:

def _impl_label(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.buildfile_path)

UnconfiguredTargetNode.deps

def UnconfiguredTargetNode.deps(
) -> list[target_label]

Gets all deps for this target. The result is a list of UnconfiguredTargetLabel.

Sample usage:

def _impl_get_deps(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.deps())

UnconfiguredTargetNode.get_attr

def UnconfiguredTargetNode.get_attr(
key: str,
/,
)

Gets the attribute from the unconfigured 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 uquery -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'))

UnconfiguredTargetNode.get_attrs

def UnconfiguredTargetNode.get_attrs(
) -> dict[str, typing.Any]

Gets the all attributes (not include speical attributes) from the unconfigured target node. For attributes that are not explicitly set, the default value is returned.

Sample usage:

def _impl_attributes(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.get_attrs())

UnconfiguredTargetNode.has_attr

def UnconfiguredTargetNode.has_attr(
key: str,
/,
) -> bool

Check if rule has the attribute.

Known attribute is always set explicitly or to default value (otherwise target would not be created) For special attributes, it will return False

Sample usage:

def _impl_attributes(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.has_attr('my_attr'))

UnconfiguredTargetNode.label

UnconfiguredTargetNode.label: target_label

Gets the label from the unconfigured target node.

Sample usage:

def _impl_label(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.label)

UnconfiguredTargetNode.oncall

UnconfiguredTargetNode.oncall: None | str

Gets the target's special attr oncall

Sample usage:

def _impl_get_oncall(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.oncall)

UnconfiguredTargetNode.rule_kind

UnconfiguredTargetNode.rule_kind: str

Gets the targets' corresponding rule's kind which is one of - normal (with no special properties) - configured (usable in a configuration context) - toolchain (only usable as a toolchain dep)

Sample usage:

def _impl_rule_kind(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.rule_kind)

UnconfiguredTargetNode.rule_type

UnconfiguredTargetNode.rule_type: str

Gets the fully qualified name of the rule for this unconfigured target node as a string. This includes the import path as well.

Sample usage:

def _impl_rule_type(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.rule_type)