Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_conda_bin():
"""Get the path to the Anaconda binary"""
conda_bin = 'conda'
# Try executing the `conda` command
if os.popen(conda_bin).read().strip() == '':
# If it fails, look for $CONDA_EXE
conda_exe = os.popen('echo $CONDA_EXE').read().strip()
# Check if it returns a valid path
if conda_exe != '' and conda_exe != '$CONDA_EXE':
# Update binary and execute again
conda_bin = conda_exe
if os.popen(conda_bin).read().strip() == '':
raise CondaError(CONDA_NOT_FOUND)
logging.info('Anaconda binary: ' + conda_bin)
return conda_bin
def read_conda_env(name=None):
"""Read the anaconda environment into a string"""
if name is None:
name = get_conda_env_name()
command = get_conda_bin() + ' env export -n ' + \
get_conda_env_name() + " --no-builds"
env_str = os.popen(command).read()
if env_str == '':
error = 'Failed to read Anaconda environment using command: "' + command + '"'
raise CondaError(error)
return env_str