Skip to content

Commit 91609e2

Browse files
authored
perf(sh-activate): avoid a duplicate pyenv-version-name call (pyenv#380)
1 parent 5509c25 commit 91609e2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

bin/pyenv-sh-activate

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,18 @@ while [ $# -gt 0 ]; do
5252
shift 1
5353
done
5454

55+
get_current_versions() {
56+
local IFS=:
57+
current_versions=($(pyenv-version-name 2>/dev/null))
58+
}
59+
5560
no_shell=
5661
versions=("$@")
62+
current_versions=()
5763
if [ -z "${versions}" ]; then
5864
no_shell=1
59-
OLDIFS="$IFS"
60-
IFS=: versions=($(pyenv-version-name 2>/dev/null))
61-
IFS="$OLDIFS"
65+
get_current_versions
66+
versions=("${current_versions[@]}")
6267
fi
6368

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

8590
if ! pyenv-virtualenv-prefix "${venv}" 1>/dev/null 2>&1; then
8691
# fallback to virtualenv of current version
87-
OLDIFS="$IFS"
88-
IFS=: current_versions=($(pyenv-version-name))
89-
IFS="$OLDIFS"
92+
[ -n "${current_versions}" ] || get_current_versions
9093
new_venv="${current_versions%/envs/*}/envs/${venv}"
9194
if pyenv-virtualenv-prefix "${new_venv}" 1>/dev/null 2>&1; then
9295
venv="${new_venv}"

0 commit comments

Comments
 (0)