Skip to main content

LazyUqueryContext

The context for performing lazy uquery operations in bxl. The functions offered on this ctx are the same behaviour as the query functions available within uquery command.

LazyUqueryContext.allpaths

def LazyUqueryContext.allpaths(
from: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
to: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
*,
filter: None | str = None,
) -> bxl.Lazy

Computes all dependency paths from from to to, with optional filter.

Example:

res = ctx.lazy.uquery().allpaths("//:foo", "//:bar", filter = "attrfilter('name', 'some_name', target_deps()")).catch().resolve()

LazyUqueryContext.attrfilter

def LazyUqueryContext.attrfilter(
attr: str,
value: str,
targets: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
) -> bxl.Lazy

Filters targets by attribute value.

Example:

res = ctx.lazy.uquery().attrfilter("name", "some_name", "//:foo").catch().resolve()

LazyUqueryContext.attrregexfilter

def LazyUqueryContext.attrregexfilter(
attr: str,
value: str,
targets: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
) -> bxl.Lazy

Filters targets by attribute value using regex matching.

Example:

res = ctx.lazy.uquery().attrregexfilter("name", "he.*lo", "//:foo").catch().resolve()

LazyUqueryContext.buildfile

def LazyUqueryContext.buildfile(
targets: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
) -> bxl.Lazy

Finds the build file(s) that define the given targets.

Example:

res = ctx.lazy.uquery().buildfile("//:foo").catch().resolve()

LazyUqueryContext.deps

def LazyUqueryContext.deps(
universe: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
depth: None | int = None,
/,
*,
filter: None | str = None,
) -> bxl.Lazy

Finds the transitive closure of dependencies.

Example:

res = ctx.lazy.uquery().deps("//:foo", 1, filter = "attrfilter('name', 'some_name', target_deps())").catch().resolve()

LazyUqueryContext.eval

def LazyUqueryContext.eval(
query: str,
/,
*,
query_args: None | target_set | list[str] = None,
) -> bxl.Lazy

Evaluates a general query string with optional query arguments.

Example:

res = ctx.lazy.uquery().eval("inputs(cell//path/to/file:target)").catch().resolve()
res = ctx.lazy.uquery().eval("inputs(%s)", query_args = ["cell//path/to/file:target"]).catch().resolve()

LazyUqueryContext.filter

def LazyUqueryContext.filter(
regex: str,
targets: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
) -> bxl.Lazy

Filters targets by name using a regex pattern.

Example:

res = ctx.lazy.uquery().filter(".*the_binary", "//:foo").catch().resolve()

LazyUqueryContext.inputs

def LazyUqueryContext.inputs(
targets: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
) -> bxl.Lazy

Finds input files for the given targets.

Example:

res = ctx.lazy.uquery().inputs("//:foo").catch().resolve()

LazyUqueryContext.kind

def LazyUqueryContext.kind(
regex: str,
targets: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
) -> bxl.Lazy

Filters targets by rule type using a regex pattern.

Example:

res = ctx.lazy.uquery().kind("cpp.*", "//:foo").catch().resolve()

LazyUqueryContext.owner

def LazyUqueryContext.owner(
files: bxl.FileSet | str | list[str] | tuple[str, ...],
/,
) -> bxl.Lazy

Finds targets that own the specified files.

Example:

res = ctx.lazy.uquery().owner("bin/TARGETS.fixture").catch().resolve()
res = ctx.lazy.uquery().owner(["bin/TARGET", "bin/kind"]).catch().resolve()

LazyUqueryContext.rdeps

def LazyUqueryContext.rdeps(
universe: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
from: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
depth: None | int = None,
/,
*,
filter: None | str = None,
) -> bxl.Lazy

Finds the transitive closure of reverse dependencies.

Example:

res = ctx.lazy.uquery().rdeps("//:universe", "//:from", 1, filter = "attrfilter('name', 'some_name', target_deps())").catch().resolve()

LazyUqueryContext.somepath

def LazyUqueryContext.somepath(
from: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
to: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
*,
filter: None | str = None,
) -> bxl.Lazy

Computes some dependency path from from to to, with optional filter.

Example:

res = ctx.lazy.uquery().somepath("//:foo", "//:bar", filter = "attrfilter('name', 'some_name', target_deps()")).catch().resolve()

LazyUqueryContext.targets_in_buildfile

def LazyUqueryContext.targets_in_buildfile(
files: bxl.FileSet | str | list[str] | tuple[str, ...],
/,
) -> bxl.Lazy

Finds targets defined in the specified build files.

Example:

res = ctx.lazy.uquery().targets_in_buildfile("bin/TARGETS.fixture").catch().resolve()
res = ctx.lazy.uquery().targets_in_buildfile(["bin/TARGETS", "lib/TARGETS"]).catch().resolve()

LazyUqueryContext.testsof

def LazyUqueryContext.testsof(
expr: TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str],
/,
) -> bxl.Lazy

Querying the test targets of the given target. It returns UnconfiguredTargetSet

Example:

def _impl(ctx: bxl.Context):
res = ctx.lazy.uquery().testsof("//:foo_lib").catch().resolve()
if res.is_ok():
nodes = res.get()
ctx.output.print(nodes)
else:
err = res.unwrap_err()
ctx.output.print(err)