mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-11 13:03:52 -05:00
check existence of ./bin/activate to detect virtualenvs to support pyvenv
This commit is contained in:
@@ -12,8 +12,30 @@ if [ -z "$PYENV_ROOT" ]; then
|
||||
fi
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
export PYENV_VERSION="$1"
|
||||
versions=($@)
|
||||
IFS=: PYENV_VERSION="${versions[*]}"
|
||||
export PYENV_VERSION
|
||||
else
|
||||
IFS=: versions=($(pyenv-version-name))
|
||||
fi
|
||||
|
||||
PYTHON_BIN="$(pyenv-which python)"
|
||||
"${PYTHON_BIN}" -c 'import sys;print(sys.real_prefix)' 2>/dev/null
|
||||
real_prefix() { # virtualenv
|
||||
local version="$1"
|
||||
PYENV_VERSION="${version}" pyenv-exec python -c 'import sys;print(sys.real_prefix)' 2>/dev/null
|
||||
}
|
||||
|
||||
VIRTUALENV_PREFIX_PATHS=()
|
||||
for version in "${versions[@]}"; do
|
||||
PREFIX="$(pyenv-prefix "${version}")"
|
||||
if [ -f "${PREFIX}/bin/activate" ]; then
|
||||
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || true)"
|
||||
if [ -d "${VIRTUALENV_PREFIX_PATH}" ]; then
|
||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
|
||||
fi
|
||||
else
|
||||
echo "pyenv: version \`${version}' is not a virtualenv" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
IFS=: echo "${VIRTUALENV_PREFIX_PATHS[*]}"
|
||||
|
||||
@@ -23,20 +23,16 @@ print_version() {
|
||||
if [ -n "${BARE}" ]; then
|
||||
echo "${version}"
|
||||
else
|
||||
echo "${version} (created from $(pyenv-virtualenv-prefix "${version}"))"
|
||||
local prefix="$(pyenv-virtualenv-prefix "${version}")"
|
||||
echo "${version} (created from ${prefix:-unknown})"
|
||||
fi
|
||||
}
|
||||
|
||||
virtualenv_version() {
|
||||
local version="$1"
|
||||
local prefix="$(pyenv-prefix "${version}")"
|
||||
[ -f "${prefix}/bin/activate" ] && "${prefix}/bin/python" -c 'import sys;sys.real_prefix' 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
versions=($(pyenv-versions --bare))
|
||||
|
||||
for version in "${versions[@]}"; do
|
||||
if virtualenv_version "${version}"; then
|
||||
prefix="$(pyenv-prefix "${version}")"
|
||||
if [ -f "${prefix}/bin/activate" ]; then
|
||||
print_version "${version}"
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user