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 ' + 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
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.environ.get("CONDA_EXE") # 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 conda_error_raiser(*args, **kwargs): raise CondaError('fake conda error')
def test_conda_error(): msg = 'This is a error' e = CondaError(msg) assert e.args == (msg, )