Skip to main content

Env.aspect_cli_version

def Env.aspect_cli_version() -> str
Returns the version of the Aspect CLI.

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.

Env.current_exe

def Env.current_exe() -> str

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.

Env.root_dir

def Env.root_dir() -> str
Returns the project root directory. This project root directory is found starting at current working directory and searching upwards through its ancestors for repository boundary marker files (such as MODULE.aspect, MODULE.bazel, MODULE.bazel.lock, REPO.bazel, WORKSPACE, or WORKSPACE.bazel). The first ancestor directory containing any of these files is considered the project root. If no such directory is found, the current directory is used as the project root.

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.

Env.var

def Env.var(
key: str,
/,
) -> None | str
Fetches the environment variable key from the current process.

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.