diff --git a/bin/pyenv-virtualenv-prefix b/bin/pyenv-virtualenv-prefix index 4c63a62..c517062 100755 --- a/bin/pyenv-virtualenv-prefix +++ b/bin/pyenv-virtualenv-prefix @@ -38,9 +38,21 @@ for version in "${versions[@]}"; do VIRTUALENV_PREFIX_PATH="${virtualenv_binpath%/bin}" else # virtualenv - shopt -s nullglob - VIRTUALENV_PREFIX_PATH="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" &1 || true)" - shopt -u nullglob + if [ -d "${PYENV_ROOT}/versions/${version}/Lib" ]; then + # jython + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/Lib" + else + if [ -d "${PYENV_ROOT}/versions/${version}/lib-python" ]; then + # pypy + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/lib-python" + else + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/lib" + fi + fi + virtualenv_orig_prefix="$(find "${virtualenv_libpath}/" -maxdepth 2 -type f -and -name "orig-prefix.txt" 2>/dev/null | head -1)" + if [ -f "${virtualenv_orig_prefix}" ]; then + VIRTUALENV_PREFIX_PATH="$(cat "${virtualenv_orig_prefix}" 2>/dev/null || true)" + fi fi fi if [ -d "${VIRTUALENV_PREFIX_PATH}" ]; then diff --git a/etc/pyenv.d/which/python-config.bash b/etc/pyenv.d/which/python-config.bash index 7d2b3eb..2785f6b 100644 --- a/etc/pyenv.d/which/python-config.bash +++ b/etc/pyenv.d/which/python-config.bash @@ -18,9 +18,21 @@ if [ ! -x "${PYENV_COMMAND_PATH}" ] && [[ "${PYENV_COMMAND_PATH##*/}" == "python 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 + if [ -d "${PYENV_ROOT}/versions/${version}/Lib" ]; then + # jython + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/Lib" + else + if [ -d "${PYENV_ROOT}/versions/${version}/lib-python" ]; then + # pypy + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/lib-python" + else + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/lib" + fi + fi + virtualenv_orig_prefix="$(find "${virtualenv_libpath}/" -maxdepth 2 -type f -and -name "orig-prefix.txt" 2>/dev/null | head -1)" + if [ -f "${virtualenv_orig_prefix}" ]; then + virtualenv_prefix="$(cat "${virtualenv_orig_prefix}" 2>/dev/null || true)" + fi fi virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}" if [ -x "${virtualenv_command_path}" ]; then diff --git a/etc/pyenv.d/which/system-site-packages.bash b/etc/pyenv.d/which/system-site-packages.bash index ee7dc91..6bfb0aa 100644 --- a/etc/pyenv.d/which/system-site-packages.bash +++ b/etc/pyenv.d/which/system-site-packages.bash @@ -22,10 +22,18 @@ if [ ! -x "${PYENV_COMMAND_PATH}" ]; then fi else # virtualenv - shopt -s nullglob - 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 [ -d "${PYENV_ROOT}/versions/${version}/Lib" ]; then + # jython + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/Lib" + else + if [ -d "${PYENV_ROOT}/versions/${version}/lib-python" ]; then + # pypy + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/lib-python" + else + virtualenv_libpath="${PYENV_ROOT}/versions/${version}/lib" + fi + fi + no_global_site_packages="$(find "${virtualenv_libpath}/" -maxdepth 2 -type f -and -name "no-global-site-packages.txt" 2>/dev/null | head -1)" if [ ! -f "${no_global_site_packages}" ]; then include_system_site_packages=1 fi diff --git a/test/prefix.bats b/test/prefix.bats index 140285a..9085b4a 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -24,6 +24,22 @@ create_virtualenv() { touch "${PYENV_ROOT}/versions/$1/bin/activate" } +create_virtualenv_jython() { + create_version "$1" + create_version "${2:-$1}" + mkdir -p "${PYENV_ROOT}/versions/$1/Lib/" + echo "${PYENV_ROOT}/versions/${2:-$1}" > "${PYENV_ROOT}/versions/$1/Lib/orig-prefix.txt" + touch "${PYENV_ROOT}/versions/$1/bin/activate" +} + +create_virtualenv_pypy() { + create_version "$1" + create_version "${2:-$1}" + mkdir -p "${PYENV_ROOT}/versions/$1/lib-python/${2:-$1}" + echo "${PYENV_ROOT}/versions/${2:-$1}" > "${PYENV_ROOT}/versions/$1/lib-python/${2:-$1}/orig-prefix.txt" + touch "${PYENV_ROOT}/versions/$1/bin/activate" +} + remove_virtualenv() { remove_version "$1" remove_version "${2:-$1}" @@ -45,18 +61,21 @@ create_conda() { create_version "${2:-$1}" touch "${PYENV_ROOT}/versions/$1/bin/conda" touch "${PYENV_ROOT}/versions/$1/bin/activate" + mkdir -p "${PYENV_ROOT}/versions/${2:-$1}/bin" + touch "${PYENV_ROOT}/versions/${2:-$1}/bin/conda" + touch "${PYENV_ROOT}/versions/${2:-$1}/bin/activate" } remove_conda() { remove_version "${2:-$1}" } -@test "display prefix with using sys.real_prefix" { - stub pyenv-version-name "echo venv27" - stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\"" - create_virtualenv "venv27" "2.7.6" +@test "display prefix of virtualenv created by virtualenv" { + stub pyenv-version-name "echo foo" + stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\"" + create_virtualenv "foo" "2.7.6" - PYENV_VERSION="venv27" run pyenv-virtualenv-prefix + PYENV_VERSION="foo" run pyenv-virtualenv-prefix assert_success assert_output <