SelectDict
In bxl, Select = bxl.SelectDict | bxl.SelectConcat
. bxl.SelectDict
is a dict-like object that represents a select. One example of this type is:
select({
"root//constraints:a": ["--foo"],
"root//constraints:b": ["--bar"],
"DEFAULT": ["baz"]
})
You can:
- Iterate over its keys (e.g.,
for key in select_dict.select_keys():
). - Iterate over key-value pairs using select_dict.select_items() (e.g.,
for key, value in select_dict.select_items():
). - Get the select entry with a string or a ProvidersLabel (e.g.,
select_dict.get_select_entry("root//constraints:a")
). - Check its type using `isinstance(select_dict, bxl.SelectDict)``.
SelectDict.get_select_entry
def SelectDict.get_select_entry(
key: ProvidersLabel | str,
/,
)
Return the entry of the select for the given key. It accepts either a string or a ProvidersLabel
.
Sample usage:
def _impl_select_dict(ctx):
node = ctx.lazy.unconfigured_target_node("root//:select_dict").resolve()
attr = node.get_attr("select_attr")
ctx.output.print(attr.get_select_entry("root//constraints:a"))
ctx.output.print(attr.get_select_entry("DEFAULT"))
# provider_label's type here is `ProvidersLabel`
ctx.output.print(attr.get_select_entry(provider_label))
SelectDict.select_items
def SelectDict.select_items(
) -> list[(ProvidersLabel | str, typing.Any)]
Return the key-value pairs of the select. The key is either a string (for DEFAULT
) or a ProvidersLabel
.
Sample usage:
def _impl_select_dict(ctx):
node = ctx.lazy.unconfigured_target_node("root//:select_dict").resolve()
attr = node.get_attr("select_attr")
for key, value in attr.select_items():
ctx.output.print(f"{key} -> {value}")
SelectDict.select_keys
def SelectDict.select_keys(
) -> list[ProvidersLabel | str]
Return the keys of SelectDict. The key is either a string (for DEFAULT
) or a ProvidersLabel
.
Sample usage:
def _impl_select_dict(ctx):
node = ctx.lazy.unconfigured_target_node("root//:select_dict").resolve()
attr = node.get_attr("select_attr")
for key in attr.select_keys():
ctx.output.print(key)