From d15ca4312c39c91ccdada539f022571dd2a3a31d Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Sun, 20 Jan 2019 09:41:32 +0100 Subject: [PATCH] [build] Improvements and fixes to get_env_directory() --- bob/devtools/build.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bob/devtools/build.py b/bob/devtools/build.py index 191a0227..34035a4f 100644 --- a/bob/devtools/build.py +++ b/bob/devtools/build.py @@ -176,13 +176,27 @@ def parse_dependencies(recipe_dir, config): def get_env_directory(conda, name): + '''Get the directory of a particular conda environment or fail silently''' cmd = [conda, 'env', 'list', '--json'] output = subprocess.check_output(cmd) data = json.loads(output) - retval = [k for k in data.get('envs', []) if k.endswith(os.sep + name)] + paths = data.get('envs', []) + + if not paths: + # real error condition, reports it at least, but no exception raising... + logger.error('No environments in conda (%s) installation?', conda) + return None + + if name in ('base', 'root'): + return paths[0] #first environment is base + + # else, must search for the path ending in ``/name`` + retval = [k for k in paths if k.endswith(os.sep + name)] if retval: return retval[0] + + # if no environment with said name is found, return ``None`` return None -- GitLab