Skip to main content
Methods available in all Bazel files, including .bzl files, BUILD, MODULE.bazel, VENDOR.bazel, and WORKSPACE.

Members

abs

Returns the absolute value of a number (a non-negative number with the same magnitude).

Parameters

all

Returns true if all elements evaluate to True or if the collection is empty. Elements are converted to boolean using the bool function.

Parameters

any

Returns true if at least one element evaluates to True. Elements are converted to boolean using the bool function.

Parameters

bool

Constructor for the bool type. It returns False if the object is None, False, an empty string (""), the number 0, or an empty collection (e.g. (), []). Otherwise, it returns True.

Parameters

dict

Creates a dictionary from an optional positional argument and an optional set of keyword arguments. In the case where the same key is given multiple times, the last value will be used. Entries supplied via keyword arguments are considered to come after entries supplied via the positional argument.

Parameters

dir

Returns a list of strings: the names of the attributes and methods of the parameter object.

Parameters

enumerate

Returns a list of pairs (two-element tuples), with the index (int) and the item from the input sequence.

Parameters

fail

Causes execution to fail with an error.

Parameters

float

Returns x as a float value.
  • If x is already a float, float returns it unchanged.* If x is a bool, float returns 1.0 for True and 0.0 for False.* If x is an int, float returns the nearest finite floating-point value to x, or an error if the magnitude is too large.* If x is a string, it must be a valid floating-point literal, or be equal (ignoring case) to NaN, Inf, or Infinity, optionally preceded by a + or - sign.
Any other value causes an error. With no argument, float() returns 0.0.

Parameters

getattr

Returns the struct’s field of the given name if it exists. If not, it either returns default (if specified) or raises an error. getattr(x, "foobar") is equivalent to x.foobar.

Parameters

hasattr

Returns True if the object x has an attribute or method of the given name, otherwise False. Example:

Parameters

hash

Return a hash value for a string. This is computed deterministically using the same algorithm as Java’s String.hashCode(), namely:
Hashing of values besides strings is not currently supported.

Parameters

int

Returns x as an int value.
  • If x is already an int, int returns it unchanged.* If x is a bool, int returns 1 for True and 0 for False.* If x is a string, it must have the format <sign><prefix><digits>. <sign> is either "+", "-", or empty (interpreted as positive). <digits> are a sequence of digits from 0 up to base - 1, where the letters a-z (or equivalently, A-Z) are used as digits for 10-35. In the case where base is 2/8/16, <prefix> is optional and may be 0b/0o/0x (or equivalently, 0B/0O/0X) respectively; if the base is any other value besides these bases or the special value 0, the prefix must be empty. In the case where base is 0, the string is interpreted as an integer literal, in the sense that one of the bases 2/8/10/16 is chosen depending on which prefix if any is used. If base is 0, no prefix is used, and there is more than one digit, the leading digit cannot be 0; this is to avoid confusion between octal and decimal. The magnitude of the number represented by the string must be within the allowed range for the int type.* If x is a float, int returns the integer value of the float, rounding towards zero. It is an error if x is non-finite (NaN or infinity).
This function fails if x is any other type, or if the value is a string not satisfying the above format. Unlike Python’s int function, this function does not allow zero arguments, and does not allow extraneous whitespace for string arguments. Examples:

Parameters

len

Returns the length of a string, sequence (such as a list or tuple), dict, set, or other iterable.

Parameters

list

Returns a new list with the same elements as the given iterable value.

Parameters

max

Returns the largest one of all given arguments. If only one positional argument is provided, it must be a non-empty iterable.It is an error if elements are not comparable (for example int with string), or if no arguments are given.

Parameters

min

Returns the smallest one of all given arguments. If only one positional argument is provided, it must be a non-empty iterable. It is an error if elements are not comparable (for example int with string), or if no arguments are given.

Parameters

print

Prints args as debug output. It will be prefixed with the string "DEBUG" and the location (file and line number) of this call. The exact way in which the arguments are converted to strings is unspecified and may change at any time. In particular, it may be different from (and more detailed than) the formatting done by str() and repr(). Using print in production code is discouraged due to the spam it creates for users. For deprecations, prefer a hard error using fail() whenever possible.

Parameters

range

Creates a list where items go from start to stop, using a step increment. If a single argument is provided, items will range from 0 to that element.

Parameters

repr

Converts any object to a string representation. This is useful for debugging.

Parameters

reversed

Returns a new, unfrozen list that contains the elements of the original iterable sequence in reversed order.

Parameters

set

Creates a new set containing the unique elements of a given iterable, preserving iteration order. If called with no argument, set() returns a new empty set. For example,

Parameters

sorted

Returns a new sorted list containing all the elements of the supplied iterable sequence. An error may occur if any pair of elements x, y may not be compared using x < y. The elements are sorted into ascending order, unless the reverse argument is True, in which case the order is descending. Sorting is stable: elements that compare equal retain their original relative order.

Parameters

str

Converts any object to string. This is useful for debugging.

Parameters

tuple

Returns a tuple with the same elements as the given iterable value.

Parameters

type

Returns the type name of its argument. This is useful for debugging and type-checking. Examples:
This function might change in the future. To write Python-compatible code and be future-proof, use it only to compare return values:

Parameters

zip

Returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The list has the size of the shortest input. With a single iterable argument, it returns a list of 1-tuples. With no arguments, it returns an empty list. Examples:

Parameters