mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
4c5ffc8d99
The `pwd` may return relative path if the `$PWD` is badly declared in bash/zsh (e.g. `PWD="." bash`). To avoid the infinite loop in `find_local_version_file()`, stop finding the version file if the target paths are same consecutively.
34 lines
867 B
Bash
Executable file
34 lines
867 B
Bash
Executable file
#!/usr/bin/env bash
|
|
# Summary: Detect the file that sets the current pyenv version
|
|
set -e
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
find_local_version_file() {
|
|
local prev root="$1"
|
|
while [ -n "$root" ] && [ "$root" != "$prev" ]; do
|
|
if [ -e "${root}/.python-version" ]; then
|
|
echo "${root}/.python-version"
|
|
exit
|
|
elif [ -e "${root}/.pyenv-version" ]; then
|
|
echo "${root}/.pyenv-version"
|
|
exit
|
|
fi
|
|
prev="${root}"
|
|
root="${root%/*}"
|
|
done
|
|
}
|
|
|
|
find_local_version_file "$PYENV_DIR"
|
|
[ "$PYENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
|
|
|
|
global_version_file="${PYENV_ROOT}/version"
|
|
|
|
if [ -e "$global_version_file" ]; then
|
|
echo "$global_version_file"
|
|
elif [ -e "${PYENV_ROOT}/global" ]; then
|
|
echo "${PYENV_ROOT}/global"
|
|
elif [ -e "${PYENV_ROOT}/default" ]; then
|
|
echo "${PYENV_ROOT}/default"
|
|
else
|
|
echo "$global_version_file"
|
|
fi
|