Browse Source

add support for .python-version file to store local python version

pull/10/head
Yamashita Yuu 11 years ago
parent
commit
684f7b7f21
2 changed files with 26 additions and 12 deletions
  1. +10
    -4
      libexec/pyenv-local
  2. +16
    -8
      libexec/pyenv-version-file

+ 10
- 4
libexec/pyenv-local View File

@ -34,15 +34,21 @@ if [ "$1" = "--complete" ]; then
fi
versions=($@)
PYENV_VERSION_FILE=".pyenv-version"
if [ "$versions" = "--unset" ]; then
rm -f "$PYENV_VERSION_FILE"
rm -f .python-version .pyenv-version
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
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"
exit 1
} >&2

+ 16
- 8
libexec/pyenv-version-file View File

@ -3,14 +3,22 @@
set -e
[ -n "$PYENV_DEBUG" ] && set -x
root="$PYENV_DIR"
while [ -n "$root" ]; do
if [ -e "${root}/.pyenv-version" ]; then
echo "${root}/.pyenv-version"
exit
fi
root="${root%/*}"
done
find_local_version_file() {
local root="$1"
while [ -n "$root" ]; do
if [ -e "${root}/.python-version" ]; then
echo "${root}/.python-version"
exit
elif [ -e "${root}/.pyenv-version" ]; then
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"

Loading…
Cancel
Save