Skip to content

Commit

Permalink
Merge pull request #328 from broadinstitute/ct-use-active-conda-env
Browse files Browse the repository at this point in the history
refactor of previous, better handle case where CONDA_DEFAULT_ENV may be defined, but CONDA_ENV_PATH is null
  • Loading branch information
tomkinsc committed Jun 1, 2016
2 parents b939d87 + ff7f077 commit 86c66dd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,9 @@ def __init__(
#
# in newer versions of conda, CONDA_DEFAULT_ENV can be used
# as it is always the full path (in earlier versions it could be name or path)
# CONDA_ENV_PATH is always a path, but not always present
if env_root_path or env or "CONDA_ENV_PATH" not in os.environ or ("CONDA_ENV_PATH" in os.environ and not len(os.environ["CONDA_ENV_PATH"])) or ("CONDA_DEFAULT_ENV" in os.environ and not len(os.environ["CONDA_DEFAULT_ENV"])):
env_root_path = env_root_path or os.path.join(util.file.get_build_path(), 'conda-tools')
env = env or 'default'
self.env_path = os.path.realpath(os.path.expanduser(
os.path.join(env_root_path, env)))
# otherwise, get path of active conda env
elif "CONDA_ENV_PATH" in os.environ and len(os.environ["CONDA_ENV_PATH"]):
# CONDA_ENV_PATH is always a path, but not always present
self.env_path = None
if "CONDA_ENV_PATH" in os.environ and len(os.environ["CONDA_ENV_PATH"]):
last_path_component = os.path.basename(os.path.normpath(os.environ["CONDA_ENV_PATH"]))
self.env_path = os.path.dirname(os.environ["CONDA_ENV_PATH"]) if last_path_component == "bin" else os.environ["CONDA_ENV_PATH"]
elif "CONDA_DEFAULT_ENV" in os.environ and len(os.environ["CONDA_DEFAULT_ENV"]):
Expand All @@ -267,6 +262,13 @@ def __init__(
self.env_path = os.path.realpath(item)
break

# if the env is being overridden, or if we could not find an active conda env
if env_root_path or env or not self.env_path:
env_root_path = env_root_path or os.path.join(util.file.get_build_path(), 'conda-tools')
env = env or 'default'
self.env_path = os.path.realpath(os.path.expanduser(
os.path.join(env_root_path, env)))

# set an env variable to the conda cache path. this env gets passed to the
# the subprocess, and the variable instructs conda where to place its cache files
conda_cache_path = conda_cache_path or os.path.join(util.file.get_build_path(), 'conda-cache')
Expand All @@ -275,7 +277,7 @@ def __init__(
old_envs_path = os.environ.get('CONDA_DEFAULT_ENV')
self.conda_env["CONDA_ENVS_PATH"] = conda_cache_path+":"+os.path.dirname(self.env_path)

_log.debug("self.env_path: %s" % self.env_path)
_log.info("Tool install conda env path: %s" % self.env_path)
self.installed = False
self._is_attempted = False

Expand Down

0 comments on commit 86c66dd

Please sign in to comment.