Merge pull request #3151 from ChristianFredrikJohnsen/fix/conda-rehash
Do not execute conda-specific code if conda is not installed
This commit is contained in:
commit
1c2a7658f0
@ -11,19 +11,33 @@ conda_exists() {
|
|||||||
[ -n "${condas}" ]
|
[ -n "${condas}" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
shims=()
|
if conda_exists; then
|
||||||
shopt -s nullglob
|
|
||||||
for shim in $(cat "${BASH_SOURCE%/*}/conda.d/"*".list" | sort | uniq | sed -e 's/#.*$//' | sed -e '/^[[:space:]]*$/d'); do
|
# Reads the list of `blacklisted` conda binaries
|
||||||
|
# from `conda.d/default.list` and creates a function
|
||||||
|
# `conda_shim` to skip creating shims for those binaries.
|
||||||
|
build_conda_exclusion_list() {
|
||||||
|
shims=()
|
||||||
|
for shim in $(sed 's/#.*$//; /^[[:space:]]*$/d' "${BASH_SOURCE%/*}/conda.d/default.list"); do
|
||||||
if [ -n "${shim##*/}" ]; then
|
if [ -n "${shim##*/}" ]; then
|
||||||
shims[${#shims[*]}]="${shim})return 0;;"
|
shims[${#shims[*]}]="${shim})return 0;;"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
shopt -u nullglob
|
eval \
|
||||||
eval "conda_shim(){ case \"\${1##*/}\" in ${shims[@]} *)return 1;;esac;}"
|
"conda_shim() {
|
||||||
|
case \"\${1##*/}\" in
|
||||||
|
${shims[@]}
|
||||||
|
*) return 1;;
|
||||||
|
esac
|
||||||
|
}"
|
||||||
|
}
|
||||||
|
|
||||||
# override `make_shims` to avoid conflict between pyenv-virtualenv's `envs.bash`
|
# override `make_shims` to avoid conflict between pyenv-virtualenv's `envs.bash`
|
||||||
# https://github.com/pyenv/pyenv-virtualenv/blob/v20160716/etc/pyenv.d/rehash/envs.bash
|
# https://github.com/pyenv/pyenv-virtualenv/blob/v20160716/etc/pyenv.d/rehash/envs.bash
|
||||||
make_shims() {
|
# The only difference between this `make_shims` and the `make_shims` defined
|
||||||
|
# in `libexec/pyenv-rehash` is that this one calls `conda_shim` to check
|
||||||
|
# if shim is blacklisted. If blacklisted -> skip creating shim.
|
||||||
|
make_shims() {
|
||||||
local file shim
|
local file shim
|
||||||
for file do
|
for file do
|
||||||
shim="${file##*/}"
|
shim="${file##*/}"
|
||||||
@ -31,9 +45,9 @@ make_shims() {
|
|||||||
register_shim "$shim"
|
register_shim "$shim"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
deregister_conda_shims() {
|
deregister_conda_shims() {
|
||||||
# adapted for Bash 4.x's associative array (#1749)
|
# adapted for Bash 4.x's associative array (#1749)
|
||||||
if declare -p registered_shims 2> /dev/null | grep -Eq '^(declare|typeset) -A'; then
|
if declare -p registered_shims 2> /dev/null | grep -Eq '^(declare|typeset) -A'; then
|
||||||
for shim in ${!registered_shims[*]}; do
|
for shim in ${!registered_shims[*]}; do
|
||||||
@ -51,8 +65,8 @@ deregister_conda_shims() {
|
|||||||
done
|
done
|
||||||
registered_shims=" ${shims[@]} "
|
registered_shims=" ${shims[@]} "
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if conda_exists; then
|
build_conda_exclusion_list
|
||||||
deregister_conda_shims
|
deregister_conda_shims
|
||||||
fi
|
fi
|
||||||
|
@ -117,6 +117,7 @@ factor
|
|||||||
false
|
false
|
||||||
fmt
|
fmt
|
||||||
fold
|
fold
|
||||||
|
greadlink
|
||||||
groups
|
groups
|
||||||
head
|
head
|
||||||
hostid
|
hostid
|
||||||
@ -192,4 +193,3 @@ who
|
|||||||
whoami
|
whoami
|
||||||
yes
|
yes
|
||||||
# --- end exclusions from coreutils
|
# --- end exclusions from coreutils
|
||||||
greadlink
|
|
Loading…
x
Reference in New Issue
Block a user