fixed to read multiple versions from PYENV_VERSION environment variable

This commit is contained in:
Yamashita Yuu 2012-09-07 19:16:42 +09:00
parent 34a4a532b2
commit 13122ca9bf
8 changed files with 69 additions and 42 deletions

View file

@ -170,15 +170,19 @@ The special version name `system` tells pyenv to use the system Python
When run without a version number, `pyenv global` reports the When run without a version number, `pyenv global` reports the
currently configured global version. currently configured global version.
_pyenv extension_ And also, you can specify multiple versions as global Python. Commands
within these Python versions are searched by specified order.
You can specify multiple versions for global Python. Commands within
these versions are searched by specified order.
$ pyenv global 2.7.3 3.2.3 $ pyenv global 2.7.3 3.2.3
$ pyenv global $ pyenv global
2.7.3 2.7.3
3.2.3 3.2.3
$ pyenv which python2.7
/home/yyuu/.pyenv/versions/2.7.3/bin/python2.7
$ pyenv which python3.2
/home/yyuu/.pyenv/versions/3.2.3/bin/python3.2
$ pyenv which python
/home/yyuu/.pyenv/versions/2.7.3/bin/python
### <a name="section_3.2"></a> 3.2 pyenv local ### <a name="section_3.2"></a> 3.2 pyenv local
@ -195,9 +199,19 @@ configured local version. You can also unset the local version:
$ pyenv local --unset $ pyenv local --unset
_pyenv extension_ And also, you can specify multiple versions as local Python. Commands
within these Python versions are searched by specified order.
You can specify multiple versions for local Python. $ pyenv local 2.7.3 3.2.3
$ pyenv local
2.7.3
3.2.3
$ pyenv which python2.7
/home/yyuu/.pyenv/versions/2.7.3/bin/python2.7
$ pyenv which python3.2
/home/yyuu/.pyenv/versions/3.2.3/bin/python3.2
$ pyenv which python
/home/yyuu/.pyenv/versions/2.7.3/bin/python
### <a name="section_3.3"></a> 3.3 pyenv shell ### <a name="section_3.3"></a> 3.3 pyenv shell
@ -219,6 +233,16 @@ prefer not to use shell integration, you may simply set the
$ export PYENV_VERSION=pypy-1.9 $ export PYENV_VERSION=pypy-1.9
And also, you can specify multiple versions via `PYENV_VERSION`
environment variable in your shell.
$ pyenv shell pypy-1.9 2.7.3
$ echo $PYENV_VERSION
pypy-1.9:2.7.3
$ pyenv version
pypy-1.9 (set by PYENV_VERSION environment variable)
2.7.3 (set by PYENV_VERSION environment variable)
### <a name="section_3.4"></a> 3.4 pyenv versions ### <a name="section_3.4"></a> 3.4 pyenv versions
Lists all Python versions known to pyenv, and shows an asterisk next to Lists all Python versions known to pyenv, and shows an asterisk next to

View file

@ -8,19 +8,19 @@ if [ "$1" = "--complete" ]; then
exec pyenv-versions --bare exec pyenv-versions --bare
fi fi
PYENV_VERSION=($@) versions=($@)
PYENV_VERSION_FILE="${PYENV_ROOT}/version" PYENV_VERSION_FILE="${PYENV_ROOT}/version"
if [ -n "$PYENV_VERSION" ]; then if [ -n "$versions" ]; then
pyenv-version-file-write "$PYENV_VERSION_FILE" "${PYENV_VERSION[@]}" pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}"
else else
IFS=: PYENV_VERSION=($( IFS=: versions=($(
pyenv-version-file-read "$PYENV_VERSION_FILE" || pyenv-version-file-read "$PYENV_VERSION_FILE" ||
pyenv-version-file-read "${PYENV_ROOT}/global" || pyenv-version-file-read "${PYENV_ROOT}/global" ||
pyenv-version-file-read "${PYENV_ROOT}/default" || pyenv-version-file-read "${PYENV_ROOT}/default" ||
echo system echo system
)) ))
for version in "${PYENV_VERSION[@]}"; do for version in "${versions[@]}"; do
echo "$version" echo "$version"
done done
fi fi

View file

@ -9,21 +9,21 @@ if [ "$1" = "--complete" ]; then
exec pyenv-versions --bare exec pyenv-versions --bare
fi fi
PYENV_VERSION=($@) versions=($@)
PYENV_VERSION_FILE=".pyenv-version" PYENV_VERSION_FILE=".pyenv-version"
if [ "$PYENV_VERSION" = "--unset" ]; then if [ "$versions" = "--unset" ]; then
rm -f "$PYENV_VERSION_FILE" rm -f "$PYENV_VERSION_FILE"
elif [ -n "$PYENV_VERSION" ]; then elif [ -n "$versions" ]; then
pyenv-version-file-write "$PYENV_VERSION_FILE" "${PYENV_VERSION[@]}" pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}"
else else
IFS=: PYENV_VERSION=($( IFS=: versions=($(
pyenv-version-file-read "$PYENV_VERSION_FILE" || pyenv-version-file-read "$PYENV_VERSION_FILE" ||
{ echo "pyenv: no local version configured for this directory" { echo "pyenv: no local version configured for this directory"
exit 1 exit 1
} >&2 } >&2
)) ))
for version in "${PYENV_VERSION[@]}"; do for version in "${versions[@]}"; do
echo "$version" echo "$version"
done done
fi fi

View file

@ -9,19 +9,21 @@ if [ "$1" = "--complete" ]; then
fi fi
if [ -n "$1" ]; then if [ -n "$1" ]; then
export PYENV_VERSION=($@) versions=($@)
IFS=: PYENV_VERSION="${versions[*]}"
export PYENV_VERSION
else else
IFS=: PYENV_VERSION=($(pyenv-version-name)) IFS=: versions=($(pyenv-version-name))
fi fi
if [ "$PYENV_VERSION" = "system" ]; then if [ "$versions" = "system" ]; then
PYTHON_PATH="$(pyenv-which python)" PYTHON_PATH="$(pyenv-which python)"
echo "${PYTHON_PATH%/*}" echo "${PYTHON_PATH%/*}"
exit exit
fi fi
PYENV_PREFIX_PATHS=() PYENV_PREFIX_PATHS=()
for version in "${PYENV_VERSION[@]}"; do for version in "${versions[@]}"; do
PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}" PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}"
if [ -d "$PYENV_PREFIX_PATH" ]; then if [ -d "$PYENV_PREFIX_PATH" ]; then
PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH") PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH")

View file

@ -9,9 +9,9 @@ if [ "$1" = "--complete" ]; then
exec pyenv-versions --bare exec pyenv-versions --bare
fi fi
version="$1" versions=("$@")
if [ -z "$version" ]; then if [ -z "$versions" ]; then
if [ -z "$PYENV_VERSION" ]; then if [ -z "$PYENV_VERSION" ]; then
echo "pyenv: no shell-specific version configured" >&2 echo "pyenv: no shell-specific version configured" >&2
exit 1 exit 1
@ -21,12 +21,13 @@ if [ -z "$version" ]; then
fi fi
fi fi
if [ "$version" = "--unset" ]; then if [ "$versions" = "--unset" ]; then
echo "unset PYENV_VERSION" echo "unset PYENV_VERSION"
exit 1 exit 1
fi fi
# Make sure the specified version is installed. # Make sure the specified version is installed.
pyenv-prefix $version >/dev/null pyenv-prefix "${versions[@]}" >/dev/null
echo "export PYENV_VERSION=\"${version}\"" IFS=: PYENV_VERSION="${versions[*]}"
echo "export PYENV_VERSION=\"${PYENV_VERSION}\""

View file

@ -4,23 +4,18 @@ set -e
PYENV_VERSION_FILE="$1" PYENV_VERSION_FILE="$1"
shift shift
PYENV_VERSION=() versions=("$@")
for version in "$@"; do
PYENV_VERSION=("${PYENV_VERSION[@]}" "$version")
done
if [ -z "$PYENV_VERSION" ] || [ -z "$PYENV_VERSION_FILE" ]; then if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then
echo "usage: pyenv write-version-file FILENAME VERSIONS..." >&2 echo "usage: pyenv write-version-file FILENAME VERSIONS..." >&2
exit 1 exit 1
fi fi
# Make sure the specified version is installed. # Make sure the specified version is installed.
for version in "${PYENV_VERSION[@]}"; do pyenv-prefix "${vesions[@]}" >/dev/null
pyenv-prefix "$version" >/dev/null
done
# Write the version out to disk. # Write the version out to disk.
rm -f "$PYENV_VERSION_FILE" rm -f "$PYENV_VERSION_FILE"
for version in "${PYENV_VERSION[@]}"; do for version in "${versions[@]}"; do
echo "$version" >> "$PYENV_VERSION_FILE" echo "$version" >> "$PYENV_VERSION_FILE"
done done

View file

@ -2,17 +2,22 @@
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
if [ -z "$PYENV_VERSION" ]; then if [ -n "$PYENV_VERSION" ]; then
# IFS=: versions=($(${PYENV_VERSION})) # this does not work on zsh without `setopt shwordsplit`.
versions=($(echo "${PYENV_VERSION}" | tr ":" " "))
else
PYENV_VERSION_FILE="$(pyenv-version-file)" PYENV_VERSION_FILE="$(pyenv-version-file)"
IFS=: PYENV_VERSION=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)) IFS=: versions=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true))
IFS=: PYENV_VERSION="${versions[*]}"
export PYENV_VERSION
fi fi
if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ] ; then if [ -z "$versions" ] || [ "$versions" = "system" ] ; then
echo "system" echo "system"
exit exit
fi fi
for version in "${PYENV_VERSION[@]}"; do for version in "${versions[@]}"; do
PYENV_VERSION_PATH="${PYENV_ROOT}/versions/${version}" PYENV_VERSION_PATH="${PYENV_ROOT}/versions/${version}"
if [ ! -d "$PYENV_VERSION_PATH" ]; then if [ ! -d "$PYENV_VERSION_PATH" ]; then
@ -21,4 +26,4 @@ for version in "${PYENV_VERSION[@]}"; do
fi fi
done done
IFS=: echo "${PYENV_VERSION[*]}" echo "${PYENV_VERSION}"

View file

@ -41,7 +41,7 @@ remove_from_path() {
} }
IFS=: versions=($(pyenv-version-name)) IFS=: versions=($(pyenv-version-name))
PYENV_VERSION=("${versions[@]}") IFS=: PYENV_VERSION="${versions[*]}"
PYENV_COMMAND="$1" PYENV_COMMAND="$1"
if [ -z "$PYENV_COMMAND" ]; then if [ -z "$PYENV_COMMAND" ]; then
@ -49,7 +49,7 @@ if [ -z "$PYENV_COMMAND" ]; then
exit 1 exit 1
fi fi
for version in "${PYENV_VERSION[@]}"; do for version in "${versions[@]}"; do
if [ "$version" = "system" ]; then if [ "$version" = "system" ]; then
PATH="$(remote_from_path "${PYENV_ROOT}/shims")" PATH="$(remote_from_path "${PYENV_ROOT}/shims")"
PYENV_COMMAND_PATH="$(command -v "$PYENV_COMMAND")" PYENV_COMMAND_PATH="$(command -v "$PYENV_COMMAND")"