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§
- dedup_
path_ var - Deduplicate colon-separated path entries.
- generate_
env_ file - Generate a new
.mlstack_envfile from scratch. - lookup_
home_ from_ passwd - Look up a user’s home directory from
/etc/passwd. - normalize_
env_ contents - Normalize the contents of a
.mlstack_envfile. - normalize_
mlstack_ env - Normalize the
.mlstack_envfile in the user’s home directory. - 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.
- resolve_
user_ home - Resolve the real user’s home directory, handling sudo context.