Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(sh-activate): avoid a pyenv-version-name call #380

Merged
merged 1 commit into from
Nov 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions bin/pyenv-sh-activate
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@ while [ $# -gt 0 ]; do
shift 1
done

get_current_versions() {
local IFS=:
current_versions=($(pyenv-version-name 2>/dev/null))
}

no_shell=
versions=("$@")
current_versions=()
if [ -z "${versions}" ]; then
no_shell=1
OLDIFS="$IFS"
IFS=: versions=($(pyenv-version-name 2>/dev/null))
IFS="$OLDIFS"
get_current_versions
versions=("${current_versions[@]}")
fi

if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
Expand All @@ -84,9 +89,7 @@ fi

if ! pyenv-virtualenv-prefix "${venv}" 1>/dev/null 2>&1; then
# fallback to virtualenv of current version
OLDIFS="$IFS"
IFS=: current_versions=($(pyenv-version-name))
IFS="$OLDIFS"
[ -n "${current_versions}" ] || get_current_versions
native-api marked this conversation as resolved.
Show resolved Hide resolved
new_venv="${current_versions%/envs/*}/envs/${venv}"
if pyenv-virtualenv-prefix "${new_venv}" 1>/dev/null 2>&1; then
venv="${new_venv}"
Expand Down