path

Report an issue View source

A structure representing a file to be used inside a repository.

Members

basename

string path.basename

A string giving the basename of the file.

dirname

path path.dirname

The parent directory of this file, or None if this file does not have a parent. May return None.

exists

bool path.exists

Returns true if the file or directory denoted by this path exists.

Note that accessing this field does not cause the path to be watched. If you'd like the repo rule or module extension to be sensitive to the path's existence, use the watch() method on the context object.

get_child

path path.get_child(*relative_paths)

Returns the path obtained by joining this path with the given relative paths.

Parameters

Parameter Description
relative_paths required
Zero or more relative path strings to append to this path with path separatorsadded as needed.

is_dir

bool path.is_dir

Returns true if this path points to a directory.

Note that accessing this field does not cause the path to be watched. If you'd like the repo rule or module extension to be sensitive to whether the path is a directory or a file, use the watch() method on the context object.

readdir

list path.readdir(watch='auto')

Returns the list of entries in the directory denoted by this path. Each entry is a path object itself.

Parameters

Parameter Description
watch default is 'auto'
whether Bazel should watch the list of entries in this directory and refetch the repository or re-evaluate the module extension next time when any changes are detected. Changes to detect include entry creation, deletion, and renaming. Note that this doesn't watch the contents of any entries in the directory.

Can be the string 'yes', 'no', or 'auto'. If set to 'auto', Bazel will only watch this directory when it is legal to do so (see repository_ctx.watch() docs for more information).

realpath

path path.realpath

Returns the canonical path for this path by repeatedly replacing all symbolic links with their referents.