Stop using virtualenv's activate script (#69)

This commit is contained in:
Yamashita, Yuu
2015-11-04 13:27:27 +00:00
parent 2ae921c253
commit 64ceee5c8e
6 changed files with 219 additions and 230 deletions

View File

@@ -70,11 +70,7 @@ if pyenv-prefix "${versions}" 1>/dev/null 2>&1; then
fi
else
version="$(pyenv-version-name)"
if [[ "${versions}" == "root" ]]; then
versions="${version%/envs/*}"
else
versions="${version%/envs/*}/envs/${versions}"
fi
versions="${version%/envs/*}/envs/${versions}"
if ! pyenv-virtualenv-prefix "${versions}" 1>/dev/null 2>&1; then
[ -n "$NOERROR" ] || echo "pyenv-virtualenv: version \`${versions}' is not an environment of anaconda/miniconda" 1>&2
echo "false"
@@ -85,21 +81,6 @@ fi
shell="${PYENV_SHELL:-${SHELL##*/}}"
prefix="$(pyenv-prefix "${versions}")"
unset conda_env
if [ -f "${prefix}/bin/conda" ]; then
if [[ "$shell" != "bash" ]] && [[ "$shell" != "zsh" ]]; then
[ -n "$NOERROR" ] || echo "pyenv-virtualenv: Only bash and zsh are supported by Anaconda/Miniconda" 1>&2
echo "false"
exit 1
fi
if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then
conda_env="${prefix##*/envs/}"
else
conda_env="root"
fi
fi
# Display setup instruction, if pyenv-virtualenv has not been initialized.
# if 'pyenv virtualenv-init -' is not found in "$profile"
if [ -z "$PYENV_VIRTUALENV_INIT" ]; then
@@ -124,29 +105,63 @@ if [ -z "$no_shell" ]; then
esac
fi
if [ -n "${conda_env}" ]; then
# anaconda/miniconda
case "${shell}" in
fish )
cat <<EOS
set -e PYENV_DEACTIVATE;
setenv PYENV_ACTIVATE "${prefix}";
EOS
;;
* )
cat <<EOS
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${prefix}";
. "${prefix%/envs/*}/bin/activate" "${conda_env}";
EOS
;;
esac
# virtualenv/pyvenv
case "${shell}" in
fish )
echo "setenv VIRTUAL_ENV \"${prefix}\";"
;;
* )
echo "export VIRTUAL_ENV=\"${prefix}\";"
;;
esac
# anaconda/miniconda
if [[ "${versions}" != "${versions%/envs/*}" ]]; then
CONDA_DEFAULT_ENV="${versions##*/envs/}"
else
# virtualenv/pyvenv
case "$shell" in
CONDA_DEFAULT_ENV="root"
fi
case "${shell}" in
fish )
echo "setenv CONDA_DEFAULT_ENV \"${CONDA_DEFAULT_ENV}\";"
;;
* )
echo "export CONDA_DEFAULT_ENV=\"${CONDA_DEFAULT_ENV}\";"
;;
esac
if [ -n "${PYTHONHOME}" ]; then
case "${shell}" in
fish )
cat <<EOS
set -e PYENV_DEACTIVATE;
setenv PYENV_ACTIVATE "${prefix}";
. "${prefix}/bin/activate.fish";
setenv _OLD_VIRTUAL_PYTHONHOME "${PYTHONHOME}";
set -e PYTHONHOME;
EOS
;;
* )
;;
* )
cat <<EOS
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${prefix}";
. "${prefix}/bin/activate";
export _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME}";
unset PYTHONHOME;
EOS
;;
esac
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT}" ]; then
: # TODO: change prompt?
fi