mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2026-09-10 07:16:18 -04:00
exits as error if the virtual environment doesn't have python executable (#104)
conda's environment might not have `python` executable. If the prefix doesn't contain `python` in it, `pyenv-which` might be ran into infinite loop if some of `which` hooks invoke `pyenv-virtualenv-prefix`.
This commit is contained in:
parent
353062df09
commit
1edff311d5
|
|
@ -37,11 +37,16 @@ for version in "${versions[@]}"; do
|
|||
exit 1
|
||||
fi
|
||||
PYENV_PREFIX_PATH="$(pyenv-prefix "${version}")"
|
||||
if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then
|
||||
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
|
||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${VIRTUALENV_PREFIX_PATH:-${PYENV_PREFIX_PATH}}")
|
||||
if [ -x "${PYENV_PREFIX_PATH}/bin/python" ]; then
|
||||
if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then
|
||||
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
|
||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${VIRTUALENV_PREFIX_PATH:-${PYENV_PREFIX_PATH}}")
|
||||
else
|
||||
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
|
||||
echo "pyenv-virtualenv: \`python' not found in version \`${version}'" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
|
|
|||
|
|
@ -6,13 +6,23 @@ setup() {
|
|||
export PYENV_ROOT="${TMP}/pyenv"
|
||||
}
|
||||
|
||||
create_virtualenv() {
|
||||
create_version() {
|
||||
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
|
||||
touch "${PYENV_ROOT}/versions/$1/bin/python"
|
||||
chmod +x "${PYENV_ROOT}/versions/$1/bin/python"
|
||||
}
|
||||
|
||||
remove_version() {
|
||||
rm -fr "${PYENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
create_virtualenv() {
|
||||
create_version "$@"
|
||||
touch "${PYENV_ROOT}/versions/$1/bin/activate"
|
||||
}
|
||||
|
||||
remove_virtualenv() {
|
||||
rm -fr "${PYENV_ROOT}/versions/$1"
|
||||
remove_version "$@"
|
||||
}
|
||||
|
||||
@test "display prefix with using sys.real_prefix" {
|
||||
|
|
@ -118,13 +128,13 @@ OUT
|
|||
@test "should fail if the version is not a virtualenv" {
|
||||
stub pyenv-version-name "echo 3.4.0"
|
||||
stub pyenv-prefix "3.4.0 : echo \"${PYENV_ROOT}/versions/3.4.0\""
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.4.0"
|
||||
create_version "3.4.0"
|
||||
|
||||
PYENV_VERSION="3.4.0" run pyenv-virtualenv-prefix
|
||||
|
||||
unstub pyenv-version-name
|
||||
unstub pyenv-prefix
|
||||
rmdir "${PYENV_ROOT}/versions/3.4.0"
|
||||
remove_version "3.4.0"
|
||||
|
||||
assert_failure
|
||||
assert_output <<OUT
|
||||
|
|
@ -139,7 +149,7 @@ OUT
|
|||
stub pyenv-exec "false" \
|
||||
"echo \"${PYENV_ROOT}/versions/3.3.3\""
|
||||
create_virtualenv "venv33"
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.4.0"
|
||||
create_version "3.4.0"
|
||||
|
||||
PYENV_VERSION="venv33:3.4.0" run pyenv-virtualenv-prefix
|
||||
|
||||
|
|
@ -147,7 +157,7 @@ OUT
|
|||
unstub pyenv-prefix
|
||||
unstub pyenv-exec
|
||||
remove_virtualenv "venv33"
|
||||
rmdir "${PYENV_ROOT}/versions/3.4.0"
|
||||
remove_version "3.4.0"
|
||||
|
||||
assert_failure
|
||||
assert_output <<OUT
|
||||
|
|
|
|||
|
|
@ -123,12 +123,16 @@ create_conda() {
|
|||
mkdir -p "${PYENV_ROOT}/versions/$version/bin"
|
||||
touch "${PYENV_ROOT}/versions/$version/bin/activate"
|
||||
touch "${PYENV_ROOT}/versions/$version/bin/conda"
|
||||
touch "${PYENV_ROOT}/versions/$version/bin/python"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/bin/conda"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/bin/python"
|
||||
local conda_env
|
||||
for conda_env; do
|
||||
mkdir -p "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin"
|
||||
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/activate"
|
||||
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/conda"
|
||||
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/python"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/conda"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/python"
|
||||
done
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue