diff --git a/etc/pyenv.d/which/python-config.bash b/etc/pyenv.d/which/python-config.bash index ed31eee..7d2b3eb 100644 --- a/etc/pyenv.d/which/python-config.bash +++ b/etc/pyenv.d/which/python-config.bash @@ -4,11 +4,28 @@ # https://github.com/yyuu/pyenv/issues/397 if [ ! -x "${PYENV_COMMAND_PATH}" ] && [[ "${PYENV_COMMAND_PATH##*/}" == "python"*"-config" ]]; then - virtualenv_prefix="$(pyenv-virtualenv-prefix 2>/dev/null || true)" - if [ -d "${virtualenv_prefix}" ]; then - virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}" - if [ -x "${virtualenv_command_path}" ]; then - PYENV_COMMAND_PATH="${virtualenv_command_path}" + OLDIFS="${IFS}" + IFS=: + version="$(pyenv-version-name)" + IFS="${OLDIFS}" + if [ -f "${PYENV_ROOT}/versions/${version}/bin/activate" ]; then + if [ -f "${PYENV_ROOT}/versions/${version}/bin/conda" ]; then + : # do nothing for conda's environments + else + if [ -f "${PYENV_ROOT}/versions/${version}/bin/pyvenv.cfg" ]; then + # pyvenv + virtualenv_binpath="$(cut -b 1-1024 "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" | sed -n '/^ *home *= */s///p' || true)" + virtualenv_prefix="${virtualenv_binpath%/bin}" + else + # virtualenv + shopt -s nullglob + virtualenv_prefix="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" &1 || true)" + shopt -u nullglob + fi + virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}" + if [ -x "${virtualenv_command_path}" ]; then + PYENV_COMMAND_PATH="${virtualenv_command_path}" + fi fi fi fi diff --git a/etc/pyenv.d/which/system-site-packages.bash b/etc/pyenv.d/which/system-site-packages.bash index 8b49790..ee7dc91 100644 --- a/etc/pyenv.d/which/system-site-packages.bash +++ b/etc/pyenv.d/which/system-site-packages.bash @@ -4,21 +4,27 @@ # https://github.com/yyuu/pyenv-virtualenv/issues/62 if [ ! -x "${PYENV_COMMAND_PATH}" ]; then - virtualenv_prefix="$(pyenv-virtualenv-prefix 2>/dev/null || true)" - if [ -d "$(pyenv-prefix)" ] && [ -d "${virtualenv_prefix}" ]; then + OLDIFS="${IFS}" + IFS=: + version="$(pyenv-version-name)" + IFS="${OLDIFS}" + if [ -f "${PYENV_ROOT}/versions/${version}/bin/activate" ]; then unset include_system_site_packages - if [ -f "$(pyenv-prefix)/bin/conda" ]; then + if [ -f "${PYENV_ROOT}/versions/${version}/bin/conda" ]; then : # do nothing for conda's environments else - if [ -f "$(pyenv-prefix)/pyvenv.cfg" ]; then + if [ -f "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" ]; then # pyvenv - if grep -q -i "include-system-site-packages *= *true" "$(pyenv-prefix)/pyvenv.cfg" 1>/dev/null 2>&1; then + virtualenv_binpath="$(cut -b 1-1024 "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" | sed -n '/^ *home *= */s///p' || true)" + virtualenv_prefix="${virtualenv_binpath%/bin}" + if grep -q -i "include-system-site-packages *= *true" "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" 1>/dev/null 2>&1; then include_system_site_packages=1 fi else # virtualenv shopt -s nullglob - no_global_site_packages="$(echo "$(pyenv-prefix)/lib/"*"/no-global-site-packages.txt")" + virtualenv_prefix="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" &1 || true)" + no_global_site_packages="$(echo "${PYENV_ROOT}/versions/${version}/lib/"*"/no-global-site-packages.txt")" shopt -u nullglob if [ ! -f "${no_global_site_packages}" ]; then include_system_site_packages=1