mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-14 20:39:55 -05:00
add support for .python-version file to store local python version
This commit is contained in:
parent
da06998457
commit
684f7b7f21
2 changed files with 26 additions and 12 deletions
|
@ -34,15 +34,21 @@ if [ "$1" = "--complete" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
versions=($@)
|
versions=($@)
|
||||||
PYENV_VERSION_FILE=".pyenv-version"
|
|
||||||
|
|
||||||
if [ "$versions" = "--unset" ]; then
|
if [ "$versions" = "--unset" ]; then
|
||||||
rm -f "$PYENV_VERSION_FILE"
|
rm -f .python-version .pyenv-version
|
||||||
elif [ -n "$versions" ]; then
|
elif [ -n "$versions" ]; then
|
||||||
pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}"
|
if [ "$(PYENV_VERSION= pyenv-version-origin)" -ef .pyenv-version ]; then
|
||||||
|
rm -f .pyenv-version
|
||||||
|
{ echo "pyenv: removed existing \`.pyenv-version' file and migrated"
|
||||||
|
echo " local version specification to \`.python-version' file"
|
||||||
|
} >&2
|
||||||
|
fi
|
||||||
|
pyenv-version-file-write .python-version "${versions[@]}"
|
||||||
else
|
else
|
||||||
IFS=: versions=($(
|
IFS=: versions=($(
|
||||||
pyenv-version-file-read "$PYENV_VERSION_FILE" ||
|
pyenv-version-file-read .python-version ||
|
||||||
|
pyenv-version-file-read .pyenv-version ||
|
||||||
{ echo "pyenv: no local version configured for this directory"
|
{ echo "pyenv: no local version configured for this directory"
|
||||||
exit 1
|
exit 1
|
||||||
} >&2
|
} >&2
|
||||||
|
|
|
@ -3,14 +3,22 @@
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
root="$PYENV_DIR"
|
find_local_version_file() {
|
||||||
while [ -n "$root" ]; do
|
local root="$1"
|
||||||
if [ -e "${root}/.pyenv-version" ]; then
|
while [ -n "$root" ]; do
|
||||||
echo "${root}/.pyenv-version"
|
if [ -e "${root}/.python-version" ]; then
|
||||||
exit
|
echo "${root}/.python-version"
|
||||||
fi
|
exit
|
||||||
root="${root%/*}"
|
elif [ -e "${root}/.pyenv-version" ]; then
|
||||||
done
|
echo "${root}/.pyenv-version"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
root="${root%/*}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
find_local_version_file "$PYENV_DIR"
|
||||||
|
[ "$PYENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
|
||||||
|
|
||||||
global_version_file="${PYENV_ROOT}/version"
|
global_version_file="${PYENV_ROOT}/version"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue