mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-07 20:31:01 -05:00
fixed to read multiple versions from PYENV_VERSION
environment variable
This commit is contained in:
parent
34a4a532b2
commit
13122ca9bf
8 changed files with 69 additions and 42 deletions
36
README.md
36
README.md
|
@ -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
|
||||
currently configured global version.
|
||||
|
||||
_pyenv extension_
|
||||
|
||||
You can specify multiple versions for global Python. Commands within
|
||||
these versions are searched by specified order.
|
||||
And also, you can specify multiple versions as global Python. Commands
|
||||
within these Python versions are searched by specified order.
|
||||
|
||||
$ pyenv global 2.7.3 3.2.3
|
||||
$ pyenv global
|
||||
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.2"></a> 3.2 pyenv local
|
||||
|
||||
|
@ -195,9 +199,19 @@ configured local version. You can also unset the local version:
|
|||
|
||||
$ 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
|
||||
|
||||
|
@ -219,6 +233,16 @@ prefer not to use shell integration, you may simply set the
|
|||
|
||||
$ 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
|
||||
|
||||
Lists all Python versions known to pyenv, and shows an asterisk next to
|
||||
|
|
|
@ -8,19 +8,19 @@ if [ "$1" = "--complete" ]; then
|
|||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
PYENV_VERSION=($@)
|
||||
versions=($@)
|
||||
PYENV_VERSION_FILE="${PYENV_ROOT}/version"
|
||||
|
||||
if [ -n "$PYENV_VERSION" ]; then
|
||||
pyenv-version-file-write "$PYENV_VERSION_FILE" "${PYENV_VERSION[@]}"
|
||||
if [ -n "$versions" ]; then
|
||||
pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}"
|
||||
else
|
||||
IFS=: PYENV_VERSION=($(
|
||||
IFS=: versions=($(
|
||||
pyenv-version-file-read "$PYENV_VERSION_FILE" ||
|
||||
pyenv-version-file-read "${PYENV_ROOT}/global" ||
|
||||
pyenv-version-file-read "${PYENV_ROOT}/default" ||
|
||||
echo system
|
||||
))
|
||||
for version in "${PYENV_VERSION[@]}"; do
|
||||
for version in "${versions[@]}"; do
|
||||
echo "$version"
|
||||
done
|
||||
fi
|
||||
|
|
|
@ -9,21 +9,21 @@ if [ "$1" = "--complete" ]; then
|
|||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
PYENV_VERSION=($@)
|
||||
versions=($@)
|
||||
PYENV_VERSION_FILE=".pyenv-version"
|
||||
|
||||
if [ "$PYENV_VERSION" = "--unset" ]; then
|
||||
if [ "$versions" = "--unset" ]; then
|
||||
rm -f "$PYENV_VERSION_FILE"
|
||||
elif [ -n "$PYENV_VERSION" ]; then
|
||||
pyenv-version-file-write "$PYENV_VERSION_FILE" "${PYENV_VERSION[@]}"
|
||||
elif [ -n "$versions" ]; then
|
||||
pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}"
|
||||
else
|
||||
IFS=: PYENV_VERSION=($(
|
||||
IFS=: versions=($(
|
||||
pyenv-version-file-read "$PYENV_VERSION_FILE" ||
|
||||
{ echo "pyenv: no local version configured for this directory"
|
||||
exit 1
|
||||
} >&2
|
||||
))
|
||||
for version in "${PYENV_VERSION[@]}"; do
|
||||
for version in "${versions[@]}"; do
|
||||
echo "$version"
|
||||
done
|
||||
fi
|
||||
|
|
|
@ -9,19 +9,21 @@ if [ "$1" = "--complete" ]; then
|
|||
fi
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
export PYENV_VERSION=($@)
|
||||
versions=($@)
|
||||
IFS=: PYENV_VERSION="${versions[*]}"
|
||||
export PYENV_VERSION
|
||||
else
|
||||
IFS=: PYENV_VERSION=($(pyenv-version-name))
|
||||
IFS=: versions=($(pyenv-version-name))
|
||||
fi
|
||||
|
||||
if [ "$PYENV_VERSION" = "system" ]; then
|
||||
if [ "$versions" = "system" ]; then
|
||||
PYTHON_PATH="$(pyenv-which python)"
|
||||
echo "${PYTHON_PATH%/*}"
|
||||
exit
|
||||
fi
|
||||
|
||||
PYENV_PREFIX_PATHS=()
|
||||
for version in "${PYENV_VERSION[@]}"; do
|
||||
for version in "${versions[@]}"; do
|
||||
PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}"
|
||||
if [ -d "$PYENV_PREFIX_PATH" ]; then
|
||||
PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH")
|
||||
|
|
|
@ -9,9 +9,9 @@ if [ "$1" = "--complete" ]; then
|
|||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
version="$1"
|
||||
versions=("$@")
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
if [ -z "$versions" ]; then
|
||||
if [ -z "$PYENV_VERSION" ]; then
|
||||
echo "pyenv: no shell-specific version configured" >&2
|
||||
exit 1
|
||||
|
@ -21,12 +21,13 @@ if [ -z "$version" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if [ "$version" = "--unset" ]; then
|
||||
if [ "$versions" = "--unset" ]; then
|
||||
echo "unset PYENV_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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}\""
|
||||
|
|
|
@ -4,23 +4,18 @@ set -e
|
|||
|
||||
PYENV_VERSION_FILE="$1"
|
||||
shift
|
||||
PYENV_VERSION=()
|
||||
for version in "$@"; do
|
||||
PYENV_VERSION=("${PYENV_VERSION[@]}" "$version")
|
||||
done
|
||||
versions=("$@")
|
||||
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
for version in "${PYENV_VERSION[@]}"; do
|
||||
pyenv-prefix "$version" >/dev/null
|
||||
done
|
||||
pyenv-prefix "${vesions[@]}" >/dev/null
|
||||
|
||||
# Write the version out to disk.
|
||||
rm -f "$PYENV_VERSION_FILE"
|
||||
for version in "${PYENV_VERSION[@]}"; do
|
||||
for version in "${versions[@]}"; do
|
||||
echo "$version" >> "$PYENV_VERSION_FILE"
|
||||
done
|
||||
|
|
|
@ -2,17 +2,22 @@
|
|||
set -e
|
||||
[ -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)"
|
||||
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
|
||||
|
||||
if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ] ; then
|
||||
if [ -z "$versions" ] || [ "$versions" = "system" ] ; then
|
||||
echo "system"
|
||||
exit
|
||||
fi
|
||||
|
||||
for version in "${PYENV_VERSION[@]}"; do
|
||||
for version in "${versions[@]}"; do
|
||||
PYENV_VERSION_PATH="${PYENV_ROOT}/versions/${version}"
|
||||
|
||||
if [ ! -d "$PYENV_VERSION_PATH" ]; then
|
||||
|
@ -21,4 +26,4 @@ for version in "${PYENV_VERSION[@]}"; do
|
|||
fi
|
||||
done
|
||||
|
||||
IFS=: echo "${PYENV_VERSION[*]}"
|
||||
echo "${PYENV_VERSION}"
|
||||
|
|
|
@ -41,7 +41,7 @@ remove_from_path() {
|
|||
}
|
||||
|
||||
IFS=: versions=($(pyenv-version-name))
|
||||
PYENV_VERSION=("${versions[@]}")
|
||||
IFS=: PYENV_VERSION="${versions[*]}"
|
||||
PYENV_COMMAND="$1"
|
||||
|
||||
if [ -z "$PYENV_COMMAND" ]; then
|
||||
|
@ -49,7 +49,7 @@ if [ -z "$PYENV_COMMAND" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
for version in "${PYENV_VERSION[@]}"; do
|
||||
for version in "${versions[@]}"; do
|
||||
if [ "$version" = "system" ]; then
|
||||
PATH="$(remote_from_path "${PYENV_ROOT}/shims")"
|
||||
PYENV_COMMAND_PATH="$(command -v "$PYENV_COMMAND")"
|
||||
|
|
Loading…
Reference in a new issue