credit.conda_env#
Shared conda environment resolution for generated job scripts.
The PBS (credit/pbs.py), Slurm (credit/slurm.py), and credit CLI
(credit/cli/_common.py) launchers all emit shell scripts that must invoke
torchrun from a specific conda environment. They previously each carried
their own copy of the resolution logic, which drifted. This module holds the
single definition.
Kept deliberately dependency-free (stdlib only, no credit imports) so the
launchers can import it without pulling in the CLI package.
Functions#
|
Return a shell expression that expands to the prefix of conda_env. |
|
Return a shell expression for |
Module Contents#
- credit.conda_env.conda_prefix_expr(conda_env: str) str#
Return a shell expression that expands to the prefix of conda_env.
A value containing a path separator is already a prefix and is returned as is. A bare environment name is resolved at run time, never at generation time, so it is not mistaken for a same-named directory in the current working directory (e.g. the repo’s
credit/package dir, which made aconda: creditconfig yield a boguscredit/bin/torchrun).Resolution order in the generated script:
$CONDA_PREFIX— set by theconda activateline the scripts emit just above this, and correct no matter where the env actually lives.conda info --envslookup by name — covers scripts that never activate. This honorsenvs_dirsfrom~/.condarc, unlike$(conda info --base)/envs/<name>, which silently produced a nonexistent path for envs kept outside the base install (e.g./glade/work/$USER/conda-envs).
- Parameters:
conda_env – A conda environment name (e.g.
"credit") or a full environment prefix path (e.g."/glade/work/me/envs/credit").- Returns:
A shell expression that expands to the environment prefix.
- credit.conda_env.torchrun_path(conda_env: str) str#
Return a shell expression for
torchruninside conda_env.- Parameters:
conda_env – A conda environment name or full prefix path, as accepted by
conda_prefix_expr().- Returns:
The
<prefix>/bin/torchrunpath, with the prefix resolved at run time for a bare environment name.