mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-12 21:43:51 -05: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:
@@ -37,11 +37,16 @@ for version in "${versions[@]}"; do
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
PYENV_PREFIX_PATH="$(pyenv-prefix "${version}")"
|
PYENV_PREFIX_PATH="$(pyenv-prefix "${version}")"
|
||||||
if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then
|
if [ -x "${PYENV_PREFIX_PATH}/bin/python" ]; then
|
||||||
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
|
if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then
|
||||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${VIRTUALENV_PREFIX_PATH:-${PYENV_PREFIX_PATH}}")
|
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
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -6,13 +6,23 @@ setup() {
|
|||||||
export PYENV_ROOT="${TMP}/pyenv"
|
export PYENV_ROOT="${TMP}/pyenv"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_virtualenv() {
|
create_version() {
|
||||||
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
|
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"
|
touch "${PYENV_ROOT}/versions/$1/bin/activate"
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_virtualenv() {
|
remove_virtualenv() {
|
||||||
rm -fr "${PYENV_ROOT}/versions/$1"
|
remove_version "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "display prefix with using sys.real_prefix" {
|
@test "display prefix with using sys.real_prefix" {
|
||||||
@@ -118,13 +128,13 @@ OUT
|
|||||||
@test "should fail if the version is not a virtualenv" {
|
@test "should fail if the version is not a virtualenv" {
|
||||||
stub pyenv-version-name "echo 3.4.0"
|
stub pyenv-version-name "echo 3.4.0"
|
||||||
stub pyenv-prefix "3.4.0 : echo \"${PYENV_ROOT}/versions/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
|
PYENV_VERSION="3.4.0" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
unstub pyenv-version-name
|
unstub pyenv-version-name
|
||||||
unstub pyenv-prefix
|
unstub pyenv-prefix
|
||||||
rmdir "${PYENV_ROOT}/versions/3.4.0"
|
remove_version "3.4.0"
|
||||||
|
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
@@ -139,7 +149,7 @@ OUT
|
|||||||
stub pyenv-exec "false" \
|
stub pyenv-exec "false" \
|
||||||
"echo \"${PYENV_ROOT}/versions/3.3.3\""
|
"echo \"${PYENV_ROOT}/versions/3.3.3\""
|
||||||
create_virtualenv "venv33"
|
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
|
PYENV_VERSION="venv33:3.4.0" run pyenv-virtualenv-prefix
|
||||||
|
|
||||||
@@ -147,7 +157,7 @@ OUT
|
|||||||
unstub pyenv-prefix
|
unstub pyenv-prefix
|
||||||
unstub pyenv-exec
|
unstub pyenv-exec
|
||||||
remove_virtualenv "venv33"
|
remove_virtualenv "venv33"
|
||||||
rmdir "${PYENV_ROOT}/versions/3.4.0"
|
remove_version "3.4.0"
|
||||||
|
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
|
|||||||
@@ -123,12 +123,16 @@ create_conda() {
|
|||||||
mkdir -p "${PYENV_ROOT}/versions/$version/bin"
|
mkdir -p "${PYENV_ROOT}/versions/$version/bin"
|
||||||
touch "${PYENV_ROOT}/versions/$version/bin/activate"
|
touch "${PYENV_ROOT}/versions/$version/bin/activate"
|
||||||
touch "${PYENV_ROOT}/versions/$version/bin/conda"
|
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/conda"
|
||||||
|
chmod +x "${PYENV_ROOT}/versions/$version/bin/python"
|
||||||
local conda_env
|
local conda_env
|
||||||
for conda_env; do
|
for conda_env; do
|
||||||
mkdir -p "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin"
|
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/activate"
|
||||||
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/conda"
|
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/conda"
|
||||||
|
chmod +x "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/python"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user