Code Monkey home page Code Monkey logo

Comments (9)

esc avatar esc commented on August 16, 2024 1

@guger good job working this one out! The suggestion looks promising, can you open a PR please and I'll give some feedback on the proposed patch? That would be the best way forward! Looking forward to see the inclusion of homebrew compatibility. 🙌

from conda-zsh-completion.

esc avatar esc commented on August 16, 2024

@guger which version are you you using? There were some recent changes in https://github.com/conda-incubator/conda-zsh-completion/blob/master/_conda#L81 -- I hope this is not a regression? I just tried with db9245508 and it works fine for me however.

This line is where the completion tries to find the environments:

https://github.com/conda-incubator/conda-zsh-completion/blob/master/_conda#L186
https://github.com/conda-incubator/conda-zsh-completion/blob/master/_conda#L207

perhaps that can help with debugging? Maybe it's not picking up the location where your environments are stored?

from conda-zsh-completion.

guger avatar guger commented on August 16, 2024

@esc Thank you for your answer!

I'm using homebrew, so my installation path is /opt/homebrew/Caskroom/miniconda/. It seems, that the variable $CONDA_EXE is not set and therefore, no environments are returned. Is there any known fix for this when using homebrew?

from conda-zsh-completion.

esc avatar esc commented on August 16, 2024

@esc Thank you for your answer!

I'm using homebrew, so my installation path is /opt/homebrew/Caskroom/miniconda/. It seems, that the variable $CONDA_EXE is not set and therefore, no environments are returned. Is there any known fix for this when using homebrew?

I am not aware of any workarounds, no. There used to be code in the completion that did a conda info --envs --json and used an inline python snippet to process the resulting JSON and turn it into a list to be used for the completion -- however, it was deemed to slow -- which is why we know have the code in __conda_envs() to hack around that to determine the environments.

There are probably multiple routes to success here, depending on how much you are willing to invest. Have a look at some of the code in the completion, you can probably take some of it an repurpose it for your needs.

For example, you could probably resurrect the conda info --envs --json and hide it behind a flag such that you can set:

zstyle ":conda_zsh_completion:*" get-envs-from-conda-info true

to enable that for your use-case? It would allow you to set that variable to true and you would then get the environments that way. You'd need to check if it's fast enough.

Or, you could make something like

zstyle ":conda_zsh_completion:*" custom-env-path /opt/homebrew/Caskroom/miniconda/envs

and then have the completion simply add that path element to the search path for environments?

Probably fixable and if you have the inclination, I'd be happy to review a PR to support this, since I presume you are probably not the only homebrew user hitting this.

from conda-zsh-completion.

guger avatar guger commented on August 16, 2024

The environments are found if I replace https://github.com/conda-incubator/conda-zsh-completion/blob/master/_conda#L186 with globalenvs=($([[ -d "/opt/homebrew/Caskroom/miniconda/base/envs" ]] && ls $ls_opts /opt/homebrew/Caskroom/miniconda/base/envs)), i.e. replacing the path with the correct homebrew miniconda environment path.

Unfortunately, this results in a weird bug when performing the autocompletion. An error/a warning is now shown when pressing tab for showing completion options:

image

Any ideas where this could be originating? I couldn't find the error string in the _conda file, so I assume this is not directly related to the implemented script.

from conda-zsh-completion.

esc avatar esc commented on August 16, 2024

@guger not sure about that __conda_ens:fg:17: points to line 17 in the __conda_envs function -- so it is probably related to something in that line.

from conda-zsh-completion.

guger avatar guger commented on August 16, 2024

@esc Well, that was due to using % instead of # for commenting. Sorting this out, autocompletion works now fine :)

So basically, for the script to work on macOS with homebrew installation, an additional path should be added for search.

The path is: /opt/homebrew/Caskroom/miniconda/base/envs.

I'm not sure how to add this, since in your current implementation, the environment variable is appended with ../bin/envs/which is not correct for homebrew/miniconda.

Probably, one could check if conda is installed in a homebrew directory and then the path could be adjusted accordingly?

from conda-zsh-completion.

guger avatar guger commented on August 16, 2024

This would be my suggestion:

__conda_envs(){
    local -a envs unnamed sort globalfirst localenvs globalenvs
    local -a conda_path
    local -a ls_opts
    local -a describe_opts
    local localenvspath
    # only parse environments.txt (including unnamed envs) if asked by the user
    zstyle -s ":conda_zsh_completion:*" show-unnamed unnamed
    zstyle -s ":conda_zsh_completion:*" sort-envs-by-time sort
    zstyle -s ":conda_zsh_completion:*" show-global-envs-first globalfirst

    ls_opts=("-1")
    if test -n "$sort"; then
        ls_opts+=("-t")
        describe_opts+=("-V")
    fi

    conda_exec=$(which conda)

    if test ${${conda_exec}#*"homebrew"} != ${conda_exec}; then
        conda_path="/opt/homebrew/Caskroom/miniconda/base/envs"
    else
        conda_path="${${CONDA_EXE}%bin/conda}/envs"
    fi

    # global envs (if exists) and base env.
    globalenvs=($([[ -d "${conda_path}" ]] && ls $ls_opts ${conda_path}))
    globalenvs+=("base")

    # local envs (if exists).
    if [[ -n "$CONDA_ENVS_PATH" ]]; then
        localenvspath="$CONDA_ENVS_PATH"
    elif [[ -n "$CONDA_ENVS_DIRS" ]]; then
        localenvspath="$CONDA_ENVS_DIRS"
    else
        localenvspath="${HOME:?}/.conda/envs"
    fi
    localenvs=($([[ -d "$localenvspath" ]] && ls $ls_opts "$localenvspath"))

    if test -n "$globalfirst"; then
        envs=($globalenvs $localenvs)
    else
        envs=($localenvs $globalenvs)
    fi

    # unmaned envs (if show-unammed).
    if test -n "$unnamed"; then
        envs+=($( (cat ${HOME:?}/.conda/environments.txt) 2>/dev/null | cut -f1 -d' ' | sed -e "s|^${PWD}|.|" | sed -e "s|^$localenvspath/||"))
    fi

    _describe $describe_opts -t envs 'conda environments' envs
}

from conda-zsh-completion.

esc avatar esc commented on August 16, 2024

fixed by #59

from conda-zsh-completion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.