I agree with the comment by @FredrikHedman that renaming scripts in the anaconda/miniconda bin
directory has the potential to be fragile. His full post led me to what I feel is a more robust answer. (Thanks!)
Rather than simply throwing away any errors thrown by calling deactivate
, we could simply condition that call on whether the function would be called versus the file. As mentioned, virtualenv and virtualenvwrapper create a function named deactivate
; the *condas call a script file of the same name.
So, in the virtualenvwrapper.sh
script, we can change the following two lines which test for whether deactivate
is merely callable:
type deactivate >/dev/null 2>&1
if [ $? -eq 0 ]
with the stricter test for whether it's a shell function:
if [ -n $ZSH_VERSION ] ; then
nametype="$(type -w deactivate)"
else
nametype="$(type -t deactivate)"
fi
if [ "${nametype##* }" == "function" ]
This change avoids triggering the spurious error noted in the original question, but doesn't risk redirecting other useful errors or output into silent oblivion.
Note the variable substitution on nametype
in the comparison. This is because the output of type -w
under zsh
returns something like "name: type
" as opposed to type -t
under bash
which returns simply "type
". The substitution deletes everything up to the last space character, if any spaces exist, leaving only the type value. This harmlessly does nothing in bash
.
(Thanks to @toprak for the zsh
test and for the correct flag, type -w
, under zsh. I look forward to more cross-shell coding tips!)
As ever, I appreciate constructive feedback and comments!
conda-deactivate
as new standard! – Clump