From 0420dc12e144333d01555ce740bf21e525309eea Mon Sep 17 00:00:00 2001 From: Douglas Mayle Date: Thu, 28 Nov 2019 18:30:35 +0100 Subject: [PATCH] Suppress error message when duplicate versions come from virtualenvs which have two names --- etc/pyenv.d/which/whence.bash | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/etc/pyenv.d/which/whence.bash b/etc/pyenv.d/which/whence.bash index 11a84fe..59855e5 100755 --- a/etc/pyenv.d/which/whence.bash +++ b/etc/pyenv.d/which/whence.bash @@ -1,8 +1,15 @@ if [ -n "$PYENV_COMMAND" ] && [ ! -x "$PYENV_COMMAND_PATH" ]; then versions=($(pyenv-whence "${PYENV_COMMAND}" 2>/dev/null || true)) if [ -n "${versions}" ]; then - if [ "${#versions[@]}" -gt 1 ]; then - echo "pyenv-implicit: found multiple ${PYENV_COMMAND} in pyenv. Use version ${versions[0]}." 1>&2 + if [ "${#versions[@]}" -gt 2 ]; then + echo "pyenv-implicit1: found multiple ${PYENV_COMMAND} in pyenv. Use version ${versions[0]}." 1>&2 + elif [ "${#versions[@]}" -gt 1 ]; then + pattern0="[1-9][0-9]*\.[0-9]*\.[0-9]*/envs/${versions[0]}$" + pattern1="[1-9][0-9]*\.[0-9]*\.[0-9]*/envs/${versions[1]}$" + # Commands in virtualenvs are always listed twice. Ignore this warning if both versions are the same virtualenv + if ! [[ "${versions[0]}" =~ $pattern1 ]] && ! [[ "${versions[1]}" =~ $pattern0 ]]; then + echo "pyenv-implicit2: found multiple ${PYENV_COMMAND} in pyenv. Use version ${versions[0]}." 1>&2 + fi fi PYENV_COMMAND_PATH="${PYENV_ROOT}/versions/${versions[0]}/bin/${PYENV_COMMAND}" fi