Skip to main content

Module path

Module path 

Source
Expand description

Tool and PATH resolution for every Subspace app.

A desktop app started from Finder, the Dock, a desktop entry or the Start Menu does not inherit the PATH a terminal has. On macOS launchd gives it /usr/bin:/bin:/usr/sbin:/sbin, so Azure CLI from Homebrew (/opt/homebrew/bin/az) is not found. The host calls apply once at startup, before any thread exists. It asks the user’s login shell (on Windows, the registry) for the PATH a terminal has and merges it with the inherited one. When the shell fails, it adds the PATH that worked last time (PathCache) and then the usual install folders of the platform (FALLBACK_DIRECTORIES). Child processes inherit the result.

The same login shell also supplies the proxy and certificate variables (network) that this process lacks. They are never written to the cache.

Every lookup of an external program uses find_tool: PATH first, then the path where the tool was found last time. Do not add other PATH lookups.

Modules§

network
The network variables a child process such as the Azure CLI gets: proxy settings and certificate bundles.

Structs§

CachedPath
A saved PATH that super::apply used because the shell failed.
CachedTool
A saved tool path that a lookup tried after PATH had no such tool.
PathCache
The cache file.
Resolved
The outcome of apply: the merged PATH and how it was made.
Startup
What the host passes to apply.

Enums§

CacheSource
Where a saved PATH came from.
Capture
The result of asking the login shell (or, on Windows, the registry) for the PATH a terminal has.
Source
Where the effective PATH came from, for display and diagnostics.
ToolError
Why find_tool found nothing. The texts match Go exec.LookPath.

Constants§

CACHED_SHELL_TIMEOUT
The shorter limit when a saved PATH can stand in for a slow shell.
CACHE_FILE
The cache file name, beside the product’s state.json.
DISABLE_ENV
Set to 0 to keep the inherited PATH.
DISABLE_ENV_ALIAS
The short name of DISABLE_ENV; either one set to 0 works.
FALLBACK_DIRECTORIES
The list for this platform.
LINUX_DIRECTORIES
Linux install folders. The deb and rpm packages put az in /usr/bin, which every PATH already holds.
MACOS_DIRECTORIES
macOS install folders.
SHELL_TIMEOUT
How long the login shell may take to start and print its environment when no saved PATH exists. This is the worst-case delay of a start: a fast shell returns at the end marker, so only a slow or stuck shell waits this long. Startup files that load nvm or endpoint-security agents can take several seconds just after the computer starts. There is one attempt, never a second one.
WINDOWS_DIRECTORIES
Windows install folders. There is no %LOCALAPPDATA% entry: the Azure CLI MSI installs per machine only, and the ZIP package goes to a folder the user chooses, which no list can know.

Functions§

applied
What apply set, if it ran.
apply⚠
Resolve the full PATH, set it and the missing network variables for this process, and save the PATH when it is known good.
cache_path
<state dir>/path-cache.json.
find_tool
Find an external program. A name with a path separator is used as given. Otherwise the first executable match wins, in this order: each PATH folder; the path where the tool was found last time, if it still exists and is executable; the platform’s usual install folders (super::FALLBACK_DIRECTORIES) that exist. The last two steps run only after super::apply: they use its cache file and its folders, so a test that never applies the startup PATH never finds a tool outside PATH. The last step also covers a start from a terminal whose PATH lacks, for example, Homebrew. A PATH or install-folder result is saved, as an absolute path, when it differs from the saved path; an install-folder result is logged once per tool.
find_tool_readonly
Resolve a tool using the same search order as find_tool without saving paths or recording and logging cache or fallback use. No process is started.
read_cache
The cache in file, or None when it is missing, unreadable, not JSON, of another schema or of the wrong shape. Such a file is replaced at the next good save. A relative tool path in the file is dropped: it depends on a working directory that is not known.
shell_timeout
The login-shell time limit: shorter when a saved PATH exists.