gforsyth / xonda

DEPRECATED: (previously a thin wrapper around conda for xonsh)
BSD 3-Clause "New" or "Revised" License
11 stars 9 forks source link

Incompatibility with anaconda 4.4.7 and above #28

Closed samueljohn closed 6 years ago

samueljohn commented 6 years ago

Conda seems to have changed how environments are de/activated.

And additionally it is no longer possible to import conda.config (they changed to relative imports). Not sure how/if to fix the latter. But the way they have changed de/activate, opens perhaps a simple way for xonsh to wrap conda. I just hacked it in my own .xonshrc like so (but unfortunately I understand too little of xonda to contribute a proper pull request). Therefore, I hope you get the idea and can implement it with greater elegance than my hack (below).

The command: full/path/to/anaconda/bin/conda shell.posix activate my_environment outputs posix compatible definitions. Same for deactivate and reactivate. The remaining commands are simply forwarded.

Conda no longer suggest to put the full path into the env since 4.4.something.


# Anaconda related stuff

$MY_ANACONDA_DIR = $HOME + '/anaconda'

def get_CONDA_PROMPT_MODIFIER():
    try:
        return $CONDA_PROMPT_MODIFIER
    except KeyError:
        return ''

$PROMPT_FIELDS['PS1'] = get_CONDA_PROMPT_MODIFIER
$PROMPT = '{PS1}{BOLD_GREEN}{user}{my_hostname}{BOLD_BLUE} {short_pwd} {BOLD_BLUE}{prompt_end}{NO_COLOR} '

def _conda(args):
    """My own wrapper for calling `conda de/activate <whatever>` """
    conda_bin = $MY_ANACONDA_DIR + '/bin/conda'
    command = args[0]
    if command in ['activate', 'deactivate', 'reactivate']:
        shell_posix_commands_from_anaconda = $(@(conda_bin) shell.posix @(a for a in args))
        return ![source-foreign -i True 'bash' @(shell_posix_commands_from_anaconda)]
    else:
        return ![@(conda_bin) @(a for a in args)]

aliases['conda'] = _conda
gforsyth commented 6 years ago

Thanks for reporting @samueljohn -- I'll try to put together a fix for this that maintains backwards compatibility. Thanks also for posting the workaround! Always nice to not have to start from zero!

gforsyth commented 6 years ago

Hey @samueljohn -- I've added a fix for this on master. I'll cut a new release tonight for pypi and conda-forge. Thanks again for raising the issue!