Skip to content

Commit

Permalink
feat: allow conda environment names to be detected from environment.yml
Browse files Browse the repository at this point in the history
Currently an error is encountered if an environment name is not
specified to `layout anaconda`. This change attempts to detect
the environment name from the environment.yml file by grepping
for the `name` property and processing the result.

The result is that .envrc files can now simply contain
`layout anaconda` as long as the local environment.yml
file specifies a `name`.

No new dependencies are introduced as `grep` is already used
and additional processing is performed using Bash parameter
expansion.
  • Loading branch information
srstsavage committed Mar 18, 2022
1 parent 6858d04 commit 77a33a0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion stdlib.sh
Expand Up @@ -856,7 +856,19 @@ layout_anaconda() {
env_loc="$env_name_or_prefix"
else
# "foo" name
env_name="$env_name_or_prefix"
# if no name was passed, try to parse it from local environment.yml
if [[ -n "$env_name_or_prefix" ]]; then
env_name="$env_name_or_prefix"
elif [[ -e environment.yml ]]; then
env_name_grep_match="$(grep -- '^name:' environment.yml)"
env_name="${env_name_grep_match/#name:*([[:space:]])}"
fi

if [[ -z "$env_name" ]]; then
log_error "Could not determine conda env name (set in environment.yml or pass explicitly)"
return 1
fi

env_loc=$("$conda" env list | grep -- '^'"$env_name"'\s')
env_loc="${env_loc##* }"
fi
Expand Down

0 comments on commit 77a33a0

Please sign in to comment.