Comments (9)
@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.
@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.
@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 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.
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](https://private-user-images.githubusercontent.com/16765393/321584506-7f14f0e9-65f1-49e0-a6fc-102bd0a2e6c5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MTMwNDcsIm5iZiI6MTcyMzgxMjc0NywicGF0aCI6Ii8xNjc2NTM5My8zMjE1ODQ1MDYtN2YxNGYwZTktNjVmMS00OWUwLWE2ZmMtMTAyYmQwYTJlNmM1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE2VDEyNTIyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJlZDY3NDNkODQxMTFkZTEwYzgzN2VjOGNjMDIzMzFmYzc1ZTE5NzcyNmYyZGE2YWY5OTQzMTA5N2M0ZGQ3YjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.p5RjrZimTAIKFGDEKIKjAFo-F2coAJ8btIjgRqL3cGE)
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.
@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.
@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.
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.
fixed by #59
from conda-zsh-completion.
Related Issues (20)
- `autoload -U compinit && compinit` has no effect unless put in the end of the file HOT 9
- Some bugs when completing -h and -V HOT 3
- Inefficient env list calculation HOT 1
- Installation is not working, any debugging tips? HOT 5
- Not working with Prezto HOT 1
- conda activate completion HOT 5
- Doesn't work like "similar" completion systems HOT 8
- Multi-user environments cannot completion HOT 2
- conda create fails on macOS HOT 1
- 'Conda activate' always completes with all environment variables HOT 15
- parse error near `^M' HOT 1
- Clarity for implementing for oh-my-zsh users HOT 4
- Create a tag for v0.10 HOT 4
- Adding custom env directory HOT 1
- Crashes when trying to complete `conda create --clone` HOT 6
- micromamba HOT 3
- Completion does not cover prefixed environemnts HOT 1
- Endless loop when completing conda info - HOT 18
- rename `master` to `main` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from conda-zsh-completion.