Skip to main content
function Env.arch
def Env.arch() -> str
Returns the CPU architecture. Returns a string describing the CPU architecture, such as “x86_64”, “aarch64”, etc. function Env.aspect_cli_version
def Env.aspect_cli_version() -> str
Returns the version of the Aspect CLI. function Env.aspect_root_dir
def Env.aspect_root_dir() -> str
Returns the Aspect project root directory — the anchor for axl / config loading. Found by walking upwards from the current working directory looking for an .aspect/version.axl or MODULE.aspect marker. Falls back to the deepest Bazel workspace marker (MODULE.bazel, WORKSPACE, etc.) so a pure-Bazel monorepo still resolves to a sane project anchor, and finally to the current working directory if no marker exists anywhere. Distinct from the Bazel workspace root — bazelrc discovery and bazel info workspace use the deepest Bazel marker, which can differ when a Bazel sub-workspace sits under an Aspect root. function Env.bazel_root_dir
def Env.bazel_root_dir() -> str
Returns the Bazel workspace root directory — the anchor for bazelrc discovery, bazel info workspace, and BES output paths. Found by walking upwards from the current working directory looking for a MODULE.bazel / WORKSPACE marker. Falls back to the deepest .aspect/version.axl or MODULE.aspect marker so a pure-Aspect workspace still resolves, and finally to the current working directory if no marker exists anywhere. Distinct from the Aspect project root — axl / config loading uses the deepest .aspect/ marker, which can differ when a Bazel sub-workspace sits under an Aspect root. function Env.current_dir
def Env.current_dir() -> str
Returns the current working directory as a path. Platform-specific behavior This function currently corresponds to the getcwd function on Unix and the GetCurrentDirectoryW function on Windows. Errors Fails if the current working directory value is invalid. Possible cases:
  • Current directory does not exist.
  • There are insufficient permissions to access the current directory.
function Env.current_exe
def Env.current_exe() -> str
function Env.git_root_dir
def Env.git_root_dir() -> None | str
Returns the git repository root — the directory containing .git — or None when not inside a git repository. function Env.home_dir
def Env.home_dir() -> None | str
Returns the path of the current user’s home directory if known. This may return None if getting the directory fails or if the platform does not have user home directories. For storing user data and configuration it is often preferable to use more specific directories. For example, XDG Base Directories on Unix or the LOCALAPPDATA and APPDATA environment variables on Windows. Unix
  • Returns the value of the ‘HOME’ environment variable if it is set (including to an empty string).
  • Otherwise, it tries to determine the home directory by invoking the getpwuid_r function using the UID of the current user. An empty home directory field returned from the getpwuid_r function is considered to be a valid value.
  • Returns None if the current user has no entry in the /etc/passwd file.
Windows
  • Returns the value of the ‘USERPROFILE’ environment variable if it is set, and is not an empty string.
  • Otherwise, GetUserProfileDirectory is used to return the path. This may change in the future.
In UWP (Universal Windows Platform) targets this function is unimplemented and always returns None. function Env.os
def Env.os() -> str
Returns the operating system name. Returns a string describing the operating system in use, such as “linux”, “macos”, “windows”, etc. function Env.remove_var
def Env.remove_var(
key: str,
/
) -> None
Removes an environment variable from the current process. Has no effect if the variable is not set. Subsequent var() calls will return None for the removed variable. function Env.set_var
def Env.set_var(
key: str,
value: str,
/
) -> None
Sets an environment variable for the current process. This affects all subsequent var() calls and any child processes spawned after this call. Use with care — environment variables are global process state. function Env.temp_dir
def Env.temp_dir() -> str
Returns the path of a temporary directory. The temporary directory may be shared among users, or between processes with different privileges; thus, the creation of any files or directories in the temporary directory must use a secure method to create a uniquely named file. Creating a file or directory with a fixed or predictable name may result in “insecure temporary file” security vulnerabilities. Consider using a crate that securely creates temporary files or directories. Note that the returned value may be a symbolic link, not a directory. Platform-specific behavior On Unix, returns the value of the TMPDIR environment variable if it is set, otherwise the value is OS-specific:
  • On Darwin-based OSes (macOS, iOS, etc) it returns the directory provided by confstr(_CS_DARWIN_USER_TEMP_DIR, ...), as recommended by Apple’s security guidelines.
  • On all other unix-based OSes, it returns /tmp.
On Windows, the behavior is equivalent to that of GetTempPath2 / GetTempPath, which this function uses internally. function Env.var
def Env.var(
key: str,
/
) -> None | str
Fetches the environment variable key from the current process. function Env.vars
def Env.vars() -> list[tuple[str, ]]
Returns an iterator of (variable, value) pairs of strings, for all the environment variables of the current process. The returned iterator contains a snapshot of the process’s environment variables at the time of this invocation. Modifications to environment variables afterwards will not be reflected in the returned iterator.