2016-05-10 00:21:53 -04:00
|
|
|
# Anaconda comes with binaries of system packages (e.g. `openssl`, `curl`).
|
|
|
|
# Creating shims for those binaries will prevent pyenv users to run those
|
|
|
|
# commands normally when not using Anaconda.
|
|
|
|
#
|
|
|
|
# This hooks is intended to skip creating shims for those executables.
|
|
|
|
|
|
|
|
conda_exists() {
|
2019-06-02 16:00:36 -04:00
|
|
|
shopt -s dotglob nullglob
|
2016-05-10 00:21:53 -04:00
|
|
|
local condas=($(echo "${PYENV_ROOT}/versions/"*"/bin/conda" "${PYENV_ROOT}/versions/"*"/envs/"*"/bin/conda"))
|
2019-06-02 16:00:36 -04:00
|
|
|
shopt -u dotglob nullglob
|
2016-05-10 00:21:53 -04:00
|
|
|
[ -n "${condas}" ]
|
|
|
|
}
|
|
|
|
|
2016-08-15 01:30:18 -04:00
|
|
|
shims=()
|
2017-07-20 20:43:23 -04:00
|
|
|
shopt -s nullglob
|
|
|
|
for shim in $(cat "${BASH_SOURCE%/*}/conda.d/"*".list" | sort | uniq | sed -e 's/#.*$//' | sed -e '/^[[:space:]]*$/d'); do
|
|
|
|
if [ -n "${shim##*/}" ]; then
|
2016-08-15 01:30:18 -04:00
|
|
|
shims[${#shims[*]}]="${shim})return 0;;"
|
|
|
|
fi
|
|
|
|
done
|
2017-07-20 20:43:23 -04:00
|
|
|
shopt -u nullglob
|
2017-07-20 20:55:11 -04:00
|
|
|
eval "conda_shim(){ case \"\${1##*/}\" in ${shims[@]} *)return 1;;esac;}"
|
2016-05-10 00:21:53 -04:00
|
|
|
|
2016-07-26 03:47:02 -04:00
|
|
|
# override `make_shims` to avoid conflict between pyenv-virtualenv's `envs.bash`
|
2017-04-16 23:59:53 -04:00
|
|
|
# https://github.com/pyenv/pyenv-virtualenv/blob/v20160716/etc/pyenv.d/rehash/envs.bash
|
2016-07-26 03:47:02 -04:00
|
|
|
make_shims() {
|
|
|
|
local file shim
|
|
|
|
for file do
|
|
|
|
shim="${file##*/}"
|
|
|
|
if ! conda_shim "${shim}" 1>&2; then
|
|
|
|
register_shim "$shim"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-05-10 00:21:53 -04:00
|
|
|
deregister_conda_shims() {
|
2021-08-20 16:15:49 -04:00
|
|
|
# adapted for Bash 4.x's associative array (#1749)
|
2023-08-28 16:57:04 -04:00
|
|
|
if declare -p registered_shims 2> /dev/null | grep -Eq '^(declare|typeset) -A'; then
|
2021-08-20 16:15:49 -04:00
|
|
|
for shim in ${!registered_shims[*]}; do
|
|
|
|
if conda_shim "${shim}" 1>&2; then
|
|
|
|
unset registered_shims[${shim}]
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
local shim
|
|
|
|
local shims=()
|
|
|
|
for shim in ${registered_shims}; do
|
|
|
|
if ! conda_shim "${shim}" 1>&2; then
|
|
|
|
shims[${#shims[*]}]="${shim}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
registered_shims=" ${shims[@]} "
|
|
|
|
fi
|
2016-05-10 00:21:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if conda_exists; then
|
|
|
|
deregister_conda_shims
|
|
|
|
fi
|