Extensions > API reference > module_ctx

module_ctx

The context of the module extension containing helper functions and information about pertinent tags across the dependency graph. You get a module_ctx object as an argument to the implementation function when you create a module extension.

execute

exec_result module_ctx.execute(arguments, timeout=600, environment={}, quiet=True, working_directory="")

Executes the command given by the list of arguments. The execution time of the command is limited by timeout (in seconds, default 600 seconds). This method returns an exec_result structure containing the output of the command. The environment map can be used to override some environment variables to be passed to the process.

Parameters

Parameter Description
arguments required
List of arguments, the first element should be the path to the program to execute.
timeout default = 600
maximum duration of the command in seconds (default is 600 seconds).
environment default = {}
force some environment variables to be set to be passed to the process.
quiet default = True
If stdout and stderr should be printed to the terminal.
working_directory default = ""
Working directory for command execution. Can be relative to the repository root or absolute.

modules

list module_ctx.modules

A list of all the Bazel modules in the external dependency graph, each of which is a bazel_module object that exposes all the tags it specified for this module extension. The iteration order of this dictionary is guaranteed to be the same as breadth-first search starting from the root module.

os

repository_os module_ctx.os

A struct to access information from the system.

path

path module_ctx.path(path)

Returns a path from a string, label or path. If the path is relative, it will resolve relative to the repository directory. If the path is a label, it will resolve to the path of the corresponding file. Note that remote repositories are executed during the analysis phase and thus cannot depends on a target result (the label should point to a non-generated file). If path is a path, it will return that path as is.

Parameters

Parameter Description
path string; or Label; or path; required
string, label or path from which to create a path from

read

string module_ctx.read(path)

Reads the content of a file on the filesystem.

Parameters

Parameter Description
path string; or Label; or path; required
path of the file to read from.

which

path module_ctx.which(program)

Returns the path of the corresponding program or None if there is no such program in the path.

Parameters

Parameter Description
program required
Program to find in the path.
May return None.