Expand description
Environment normalization, home directory resolution, and Python interpreter discovery.
Provides:
- Home directory resolution with sudo context handling (VAL-PLAT-017)
.mlstack_envnormalization producing consistent, idempotent environment (VAL-PLAT-018)- Python interpreter discovery across venvs, conda, and system paths (VAL-PLAT-020)
§Sudo Context
When running under sudo, the real user’s home directory is resolved via:
MLSTACK_USER_HOMEenv var$HOME(if not/root)/etc/passwdlookup forSUDO_USER/USER/LOGNAME
§Python Discovery Priority
MLSTACK_PYTHON_BIN/UV_PYTHONenv vars- Active virtualenv (
VIRTUAL_ENV) - Conda environments
- System Python (
/usr/bin/python3, etc.) - Component venvs (
~/rocm_venv/bin/python)
§.mlstack_env Normalization
The env file is idempotent: running normalization twice produces the same output as running it once. Duplicate PATH/LD_LIBRARY_PATH entries are removed, and all required variables are present.
Enums§
- EnvUpdate
Result - Result of
.mlstack_envnormalization.
Functions§
- command_
on_ path - Is
cmdexecutable found onPATH? (Dependency-free; does not spawn.) - create_
global_ env - Create the managed global environment at
~/.mlstack/global/. - dedup_
path_ var - Deduplicate colon-separated path entries.
- ensure_
global_ venv - Create the managed global venv at
~/.mlstack/global/if it does not yet exist, usingbootstrap_python(a discovered system/uv interpreter) as the base. Returns the path to the global venv’spython. - ensure_
mlstack_ dirs - Ensure the
~/.mlstack/root and its standard subdirs exist. - ensure_
named_ venv - Create the managed NAMED env at
~/.mlstack/envs/<name>/if absent (Tenet 1: install-to-env isolation). Returns the path to itspython. - generate_
env_ file - Generate a new
.mlstack_envfile from scratch. - lookup_
home_ from_ passwd - Look up a user’s home directory from
/etc/passwd. - mlstack_
cache_ dir - The cache directory:
~/.mlstack/cache/. - mlstack_
env_ dir - A specific named env:
~/.mlstack/envs/<name>/. - mlstack_
envs_ dir - The named-envs directory:
~/.mlstack/envs/. - mlstack_
global_ dir - The managed global default environment:
~/.mlstack/global/. - mlstack_
global_ python - The Python binary of the managed global env:
~/.mlstack/global/bin/python. - mlstack_
logs_ dir - The logs directory:
~/.mlstack/logs/. - mlstack_
root - The single ML Stack root directory:
~/.mlstack/. - mlstack_
triton_ dir - The triton home directory:
~/.mlstack/triton/. - normalize_
env_ contents - Normalize the contents of a
.mlstack_envfile. - normalize_
mlstack_ env - Normalize the
.mlstack_envfile in the user’s home directory. - offer_
global_ prepend - Offer to prepend the global env to the user’s shell rc.
- offer_
mlstack_ env_ source - Idempotently append a
source ~/.mlstack_envline to~/.bashrcand~/.zshrcso the device-filtered ROCm env (iGPUs excluded) is auto-sourced on every POSIX shell launch — the “persistent env” the Global install option promises. Fish is NOT handled here: it auto-loads theconf.d/mlstack_env.fishwritten byensure_mlstack_env. - python_
interpreters - Discover Python interpreter paths in priority order, deduplicated.
- python_
interpreters_ for_ home - Discover Python interpreters for a given home directory (testable).
- resolve_
canonical_ python_ bin - Resolve the canonical Python binary path — the single interpreter ALL ML components install into.
- resolve_
managed_ python - Resolve a managed Python interpreter (≤3.13, prefer 3.12) via backend.
- resolve_
user_ home - Resolve the real user’s home directory, handling sudo context.
- write_
activate_ snippets - Write activation snippets to
~/.mlstack/global/.