mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-12 13:33:52 -05:00
Fix wrong library path for virtualenv on PyPy/Jython (fixes #134)
This commit is contained in:
@@ -38,9 +38,21 @@ for version in "${versions[@]}"; do
|
|||||||
VIRTUALENV_PREFIX_PATH="${virtualenv_binpath%/bin}"
|
VIRTUALENV_PREFIX_PATH="${virtualenv_binpath%/bin}"
|
||||||
else
|
else
|
||||||
# virtualenv
|
# virtualenv
|
||||||
shopt -s nullglob
|
if [ -d "${PYENV_ROOT}/versions/${version}/Lib" ]; then
|
||||||
VIRTUALENV_PREFIX_PATH="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" </dev/null 2>&1 || true)"
|
# jython
|
||||||
shopt -u nullglob
|
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
|
||||||
fi
|
fi
|
||||||
if [ -d "${VIRTUALENV_PREFIX_PATH}" ]; then
|
if [ -d "${VIRTUALENV_PREFIX_PATH}" ]; then
|
||||||
|
|||||||
@@ -18,9 +18,21 @@ if [ ! -x "${PYENV_COMMAND_PATH}" ] && [[ "${PYENV_COMMAND_PATH##*/}" == "python
|
|||||||
virtualenv_prefix="${virtualenv_binpath%/bin}"
|
virtualenv_prefix="${virtualenv_binpath%/bin}"
|
||||||
else
|
else
|
||||||
# virtualenv
|
# virtualenv
|
||||||
shopt -s nullglob
|
if [ -d "${PYENV_ROOT}/versions/${version}/Lib" ]; then
|
||||||
virtualenv_prefix="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" </dev/null 2>&1 || true)"
|
# jython
|
||||||
shopt -u nullglob
|
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
|
fi
|
||||||
virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}"
|
virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}"
|
||||||
if [ -x "${virtualenv_command_path}" ]; then
|
if [ -x "${virtualenv_command_path}" ]; then
|
||||||
|
|||||||
@@ -22,10 +22,18 @@ if [ ! -x "${PYENV_COMMAND_PATH}" ]; then
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# virtualenv
|
# virtualenv
|
||||||
shopt -s nullglob
|
if [ -d "${PYENV_ROOT}/versions/${version}/Lib" ]; then
|
||||||
virtualenv_prefix="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" </dev/null 2>&1 || true)"
|
# jython
|
||||||
no_global_site_packages="$(echo "${PYENV_ROOT}/versions/${version}/lib/"*"/no-global-site-packages.txt")"
|
virtualenv_libpath="${PYENV_ROOT}/versions/${version}/Lib"
|
||||||
shopt -u nullglob
|
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
|
if [ ! -f "${no_global_site_packages}" ]; then
|
||||||
include_system_site_packages=1
|
include_system_site_packages=1
|
||||||
fi
|
fi
|
||||||
|
|||||||
130
test/prefix.bats
130
test/prefix.bats
@@ -24,6 +24,22 @@ create_virtualenv() {
|
|||||||
touch "${PYENV_ROOT}/versions/$1/bin/activate"
|
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_virtualenv() {
|
||||||
remove_version "$1"
|
remove_version "$1"
|
||||||
remove_version "${2:-$1}"
|
remove_version "${2:-$1}"
|
||||||
@@ -45,18 +61,21 @@ create_conda() {
|
|||||||
create_version "${2:-$1}"
|
create_version "${2:-$1}"
|
||||||
touch "${PYENV_ROOT}/versions/$1/bin/conda"
|
touch "${PYENV_ROOT}/versions/$1/bin/conda"
|
||||||
touch "${PYENV_ROOT}/versions/$1/bin/activate"
|
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_conda() {
|
||||||
remove_version "${2:-$1}"
|
remove_version "${2:-$1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "display prefix with using sys.real_prefix" {
|
@test "display prefix of virtualenv created by virtualenv" {
|
||||||
stub pyenv-version-name "echo venv27"
|
stub pyenv-version-name "echo foo"
|
||||||
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
|
||||||
create_virtualenv "venv27" "2.7.6"
|
create_virtualenv "foo" "2.7.6"
|
||||||
|
|
||||||
PYENV_VERSION="venv27" run pyenv-virtualenv-prefix
|
PYENV_VERSION="foo" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
@@ -65,17 +84,51 @@ OUT
|
|||||||
|
|
||||||
unstub pyenv-version-name
|
unstub pyenv-version-name
|
||||||
unstub pyenv-prefix
|
unstub pyenv-prefix
|
||||||
remove_virtualenv "venv27" "2.7.6"
|
remove_virtualenv "foo" "2.7.6"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "display prefixes with using sys.real_prefix" {
|
@test "display prefix of virtualenv created by virtualenv (pypy)" {
|
||||||
stub pyenv-version-name "echo venv27:venv32"
|
stub pyenv-version-name "echo foo"
|
||||||
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\"" \
|
stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
|
||||||
"venv32 : echo \"${PYENV_ROOT}/versions/venv32\""
|
create_virtualenv_pypy "foo" "pypy-4.0.1"
|
||||||
create_virtualenv "venv27" "2.7.6"
|
|
||||||
create_virtualenv "venv32" "3.2.1"
|
|
||||||
|
|
||||||
PYENV_VERSION="venv27:venv32" run pyenv-virtualenv-prefix
|
PYENV_VERSION="foo" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
${PYENV_ROOT}/versions/pypy-4.0.1
|
||||||
|
OUT
|
||||||
|
|
||||||
|
unstub pyenv-version-name
|
||||||
|
unstub pyenv-prefix
|
||||||
|
remove_virtualenv "foo" "pypy-4.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "display prefix of virtualenv created by virtualenv (jython)" {
|
||||||
|
stub pyenv-version-name "echo foo"
|
||||||
|
stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
|
||||||
|
create_virtualenv_jython "foo" "jython-2.7.0"
|
||||||
|
|
||||||
|
PYENV_VERSION="foo" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
${PYENV_ROOT}/versions/jython-2.7.0
|
||||||
|
OUT
|
||||||
|
|
||||||
|
unstub pyenv-version-name
|
||||||
|
unstub pyenv-prefix
|
||||||
|
remove_virtualenv "foo" "jython-2.7.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "display prefixes of virtualenv created by virtualenv" {
|
||||||
|
stub pyenv-version-name "echo foo:bar"
|
||||||
|
stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\"" \
|
||||||
|
"bar : echo \"${PYENV_ROOT}/versions/bar\""
|
||||||
|
create_virtualenv "foo" "2.7.6"
|
||||||
|
create_virtualenv "bar" "3.2.1"
|
||||||
|
|
||||||
|
PYENV_VERSION="foo:bar" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
@@ -84,16 +137,16 @@ OUT
|
|||||||
|
|
||||||
unstub pyenv-version-name
|
unstub pyenv-version-name
|
||||||
unstub pyenv-prefix
|
unstub pyenv-prefix
|
||||||
remove_virtualenv "venv27" "2.7.6"
|
remove_virtualenv "foo" "2.7.6"
|
||||||
remove_virtualenv "venv32" "3.2.1"
|
remove_virtualenv "bar" "3.2.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "display prefix with using sys.base_prefix" {
|
@test "display prefix of virtualenv created by pyvenv" {
|
||||||
stub pyenv-version-name "echo venv33"
|
stub pyenv-version-name "echo foo"
|
||||||
stub pyenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/venv33\""
|
stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\""
|
||||||
create_virtualenv "venv33" "3.3.3"
|
create_pyvenv "foo" "3.3.3"
|
||||||
|
|
||||||
PYENV_VERSION="venv33" run pyenv-virtualenv-prefix
|
PYENV_VERSION="foo" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
@@ -102,17 +155,17 @@ OUT
|
|||||||
|
|
||||||
unstub pyenv-version-name
|
unstub pyenv-version-name
|
||||||
unstub pyenv-prefix
|
unstub pyenv-prefix
|
||||||
remove_virtualenv "venv33" "3.3.3"
|
remove_pyvenv "foo" "3.3.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "display prefixes with using sys.base_prefix" {
|
@test "display prefixes of virtualenv created by pyvenv" {
|
||||||
stub pyenv-version-name "echo venv33:venv34"
|
stub pyenv-version-name "echo foo:bar"
|
||||||
stub pyenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/venv33\"" \
|
stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\"" \
|
||||||
"venv34 : echo \"${PYENV_ROOT}/versions/venv34\""
|
"bar : echo \"${PYENV_ROOT}/versions/bar\""
|
||||||
create_virtualenv "venv33" "3.3.3"
|
create_pyvenv "foo" "3.3.3"
|
||||||
create_virtualenv "venv34" "3.4.0"
|
create_pyvenv "bar" "3.4.0"
|
||||||
|
|
||||||
PYENV_VERSION="venv33:venv34" run pyenv-virtualenv-prefix
|
PYENV_VERSION="foo:bar" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
@@ -121,8 +174,25 @@ OUT
|
|||||||
|
|
||||||
unstub pyenv-version-name
|
unstub pyenv-version-name
|
||||||
unstub pyenv-prefix
|
unstub pyenv-prefix
|
||||||
remove_virtualenv "venv33" "3.3.3"
|
remove_pyvenv "foo" "3.3.3"
|
||||||
remove_virtualenv "venv34" "3.4.0"
|
remove_pyvenv "bar" "3.4.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "display prefix of virtualenv created by conda" {
|
||||||
|
stub pyenv-version-name "echo miniconda3-3.16.0/envs/foo"
|
||||||
|
stub pyenv-prefix "miniconda3-3.16.0/envs/foo : echo \"${PYENV_ROOT}/versions/miniconda3-3.16.0/envs/foo\""
|
||||||
|
create_conda "miniconda3-3.16.0/envs/foo" "miniconda3-3.16.0"
|
||||||
|
|
||||||
|
PYENV_VERSION="miniconda3-3.16.0/envs/foo" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
${PYENV_ROOT}/versions/miniconda3-3.16.0/envs/foo
|
||||||
|
OUT
|
||||||
|
|
||||||
|
unstub pyenv-version-name
|
||||||
|
unstub pyenv-prefix
|
||||||
|
remove_conda "miniconda3-3.16.0/envs/foo" "miniconda3-3.16.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "should fail if the version is the system" {
|
@test "should fail if the version is the system" {
|
||||||
|
|||||||
Reference in New Issue
Block a user