2012-08-31 02:23:41 -04:00
|
|
|
#!/usr/bin/env bash
|
2013-01-18 03:41:41 -05:00
|
|
|
# Summary: Detect the file that sets the current pyenv version
|
2012-08-31 02:23:41 -04:00
|
|
|
set -e
|
|
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
|
2013-01-18 03:55:46 -05:00
|
|
|
find_local_version_file() {
|
2014-01-06 02:37:21 -05:00
|
|
|
local root="$1"
|
|
|
|
while [ -n "$root" ]; do
|
2013-01-18 03:55:46 -05:00
|
|
|
if [ -e "${root}/.python-version" ]; then
|
|
|
|
echo "${root}/.python-version"
|
|
|
|
exit
|
|
|
|
elif [ -e "${root}/.pyenv-version" ]; then
|
|
|
|
echo "${root}/.pyenv-version"
|
|
|
|
exit
|
|
|
|
fi
|
2014-01-06 02:37:21 -05:00
|
|
|
[ "${root}" = "${root%/*}" ] && break
|
2013-01-18 03:55:46 -05:00
|
|
|
root="${root%/*}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
find_local_version_file "$PYENV_DIR"
|
|
|
|
[ "$PYENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
|
2012-08-31 02:23:41 -04:00
|
|
|
|
|
|
|
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
|