activate "root" environment of anaconda/miniconda if environment name is not given

This commit is contained in:
Yamashita, Yuu
2015-07-19 04:19:05 +09:00
parent 25395f0331
commit cdbf7c9972
6 changed files with 34 additions and 37 deletions

View File

@@ -69,7 +69,12 @@ if pyenv-prefix "${versions}" 1>/dev/null 2>&1; then
exit 1
fi
else
versions="$(pyenv-version-name)/envs/${versions}"
version="$(pyenv-version-name)"
if [[ "${versions}" == "root" ]]; then
versions="${version%/envs/*}"
else
versions="${version%/envs/*}/envs/${versions}"
fi
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"
@@ -83,23 +88,16 @@ prefix="$(pyenv-prefix "${versions}")"
unset conda_env
if [ -f "${prefix}/bin/conda" ]; then
if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then
case "$shell" in
bash )
conda_env="${prefix##*/envs/}"
;;
zsh )
conda_env="${prefix##*/envs/}"
;;
* )
echo "false"
exit 1
;;
esac
else
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.
@@ -131,7 +129,7 @@ if [ -n "${conda_env}" ]; then
cat <<EOS
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${prefix}";
. "${prefix%/envs/*}/bin/activate" "${versions##*/}";
. "${prefix%/envs/*}/bin/activate" "${conda_env}";
EOS
else
# virtualenv/pyvenv

View File

@@ -33,23 +33,16 @@ prefix="${PYENV_ACTIVATE:-${VIRTUAL_ENV}}"
unset conda_env
if [ -f "${prefix}/bin/conda" ]; then
if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then
case "$shell" in
bash )
conda_env="${prefix##*/envs/}"
;;
zsh )
conda_env="${prefix##*/envs/}"
;;
* )
echo "false"
exit 1
;;
esac
else
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
if [ -n "${conda_env}" ]; then

View File

@@ -50,8 +50,7 @@ for version_string in "${versions[@]}"; do
exit 1
fi
else
echo "pyenv-virtualenv: version \`${version_string}' is not a virtualenv" 1>&2
exit 1
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${PREFIX}")
fi
else
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"

View File

@@ -51,10 +51,9 @@ for version in $(pyenv-versions --bare); do
virtualenv_prefix="$(pyenv-virtualenv-prefix "${version}" 2>/dev/null || true)"
if [ -d "${virtualenv_prefix}" ]; then
print_version "${version}" " (created from ${virtualenv_prefix})"
else
# envs of anaconda/miniconda
prefix="$(pyenv-prefix "${version}")"
if [ -f "${prefix}/bin/activate" ] && [ -f "${prefix}/bin/conda" ]; then
if [ -f "${prefix}/bin/conda" ]; then
# envs of anaconda/miniconda
shopt -s nullglob
for conda_env in "${prefix}/envs/"*; do
print_version "${version##*/}${conda_env#${prefix}}" " (created from ${prefix})"