mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-07 20:31:01 -05:00
Merge remote-tracking branch 'rbenv/master'
Conflicts: README.md libexec/pyenv---version libexec/pyenv-init libexec/rbenv libexec/rbenv-sh-shell libexec/rbenv-which test/init.bats test/shell.bats
This commit is contained in:
commit
3fd23431af
7 changed files with 108 additions and 26 deletions
|
@ -12,7 +12,7 @@
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
version="1.0.10"
|
version="1.1.0"
|
||||||
git_revision=""
|
git_revision=""
|
||||||
|
|
||||||
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q pyenv; then
|
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q pyenv; then
|
||||||
|
|
|
@ -86,8 +86,8 @@ mkdir -p "${PYENV_ROOT}/"{shims,versions}
|
||||||
|
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish )
|
fish )
|
||||||
echo "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
|
echo "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
||||||
echo "setenv PYENV_SHELL $shell"
|
echo "set -gx PYENV_SHELL $shell"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
|
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
|
||||||
|
@ -97,10 +97,7 @@ esac
|
||||||
|
|
||||||
completion="${root}/completions/pyenv.${shell}"
|
completion="${root}/completions/pyenv.${shell}"
|
||||||
if [ -r "$completion" ]; then
|
if [ -r "$completion" ]; then
|
||||||
case "$shell" in
|
echo "source '$completion'"
|
||||||
fish ) echo ". '$completion'" ;;
|
|
||||||
* ) echo "source '$completion'" ;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$no_rehash" ]; then
|
if [ -z "$no_rehash" ]; then
|
||||||
|
@ -117,7 +114,7 @@ function pyenv
|
||||||
|
|
||||||
switch "\$command"
|
switch "\$command"
|
||||||
case ${commands[*]}
|
case ${commands[*]}
|
||||||
. (pyenv "sh-\$command" \$argv|psub)
|
source (pyenv "sh-\$command" \$argv|psub)
|
||||||
case '*'
|
case '*'
|
||||||
command pyenv "\$command" \$argv
|
command pyenv "\$command" \$argv
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#
|
#
|
||||||
# Summary: Set or show the shell-specific Python version
|
# Summary: Set or show the shell-specific Python version
|
||||||
#
|
#
|
||||||
# Usage: pyenv shell <version>
|
# Usage: pyenv shell <version>...
|
||||||
|
# pyenv shell -
|
||||||
# pyenv shell --unset
|
# pyenv shell --unset
|
||||||
#
|
#
|
||||||
# Sets a shell-specific Python version by setting the `PYENV_VERSION'
|
# Sets a shell-specific Python version by setting the `PYENV_VERSION'
|
||||||
|
@ -12,6 +13,11 @@
|
||||||
# <version> should be a string matching a Python version known to pyenv.
|
# <version> should be a string matching a Python version known to pyenv.
|
||||||
# The special version string `system' will use your default system Python.
|
# The special version string `system' will use your default system Python.
|
||||||
# Run `pyenv versions' for a list of available Python versions.
|
# Run `pyenv versions' for a list of available Python versions.
|
||||||
|
#
|
||||||
|
# When `-` is passed instead of the version string, the previously set
|
||||||
|
# version will be restored. With `--unset`, the `PYENV_VERSION`
|
||||||
|
# environment variable gets unset, restoring the environment to the
|
||||||
|
# state before the first `pyenv shell` call.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
@ -31,7 +37,7 @@ if [ -z "$versions" ]; then
|
||||||
echo "pyenv: no shell-specific version configured" >&2
|
echo "pyenv: no shell-specific version configured" >&2
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "echo \"\$PYENV_VERSION\""
|
echo 'echo "$PYENV_VERSION"'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -39,28 +45,76 @@ fi
|
||||||
if [ "$versions" = "--unset" ]; then
|
if [ "$versions" = "--unset" ]; then
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish )
|
fish )
|
||||||
|
echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"'
|
||||||
echo "set -e PYENV_VERSION"
|
echo "set -e PYENV_VERSION"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
|
echo 'PYENV_VERSION_OLD="$PYENV_VERSION"'
|
||||||
echo "unset PYENV_VERSION"
|
echo "unset PYENV_VERSION"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$versions" = "-" ]; then
|
||||||
|
case "$shell" in
|
||||||
|
fish )
|
||||||
|
cat <<EOS
|
||||||
|
if set -q PYENV_VERSION_OLD
|
||||||
|
if [ -n "\$PYENV_VERSION_OLD" ]
|
||||||
|
set PYENV_VERSION_OLD_ "\$PYENV_VERSION"
|
||||||
|
set -gx PYENV_VERSION "\$PYENV_VERSION_OLD"
|
||||||
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION_OLD_"
|
||||||
|
set -e PYENV_VERSION_OLD_
|
||||||
|
else
|
||||||
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
||||||
|
set -e PYENV_VERSION
|
||||||
|
end
|
||||||
|
else
|
||||||
|
echo "pyenv: PYENV_VERSION_OLD is not set" >&2
|
||||||
|
false
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
cat <<EOS
|
||||||
|
if [ -n "\${PYENV_VERSION_OLD+x}" ]; then
|
||||||
|
if [ -n "\$PYENV_VERSION_OLD" ]; then
|
||||||
|
PYENV_VERSION_OLD_="\$PYENV_VERSION"
|
||||||
|
export PYENV_VERSION="\$PYENV_VERSION_OLD"
|
||||||
|
PYENV_VERSION_OLD="\$PYENV_VERSION_OLD_"
|
||||||
|
unset PYENV_VERSION_OLD_
|
||||||
|
else
|
||||||
|
PYENV_VERSION_OLD="\$PYENV_VERSION"
|
||||||
|
unset PYENV_VERSION
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "pyenv: PYENV_VERSION_OLD is not set" >&2
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
EOS
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
# Make sure the specified version is installed.
|
# Make sure the specified version is installed.
|
||||||
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=: version="${versions[*]}"
|
IFS=: version="${versions[*]}"
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
|
if [ "$version" != "$PYENV_VERSION" ]; then
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish )
|
fish )
|
||||||
echo "setenv PYENV_VERSION \"${version}\""
|
echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"'
|
||||||
|
echo "set -gx PYENV_VERSION \"$version\""
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
|
echo 'PYENV_VERSION_OLD="$PYENV_VERSION"'
|
||||||
echo "export PYENV_VERSION=\"${version}\""
|
echo "export PYENV_VERSION=\"${version}\""
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "false"
|
echo "false"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -18,7 +18,7 @@ fi
|
||||||
remove_from_path() {
|
remove_from_path() {
|
||||||
local path_to_remove="$1"
|
local path_to_remove="$1"
|
||||||
local path_before
|
local path_before
|
||||||
local result=":$PATH:"
|
local result=":${PATH//\~/$HOME}:"
|
||||||
while [ "$path_before" != "$result" ]; do
|
while [ "$path_before" != "$result" ]; do
|
||||||
path_before="$result"
|
path_before="$result"
|
||||||
result="${result//:$path_to_remove:/:}"
|
result="${result//:$path_to_remove:/:}"
|
||||||
|
|
3
src/configure
vendored
3
src/configure
vendored
|
@ -21,6 +21,9 @@ case "$(uname -s)" in
|
||||||
Darwin* )
|
Darwin* )
|
||||||
host_os="darwin$(uname -r)"
|
host_os="darwin$(uname -r)"
|
||||||
;;
|
;;
|
||||||
|
FreeBSD* )
|
||||||
|
host_os="freebsd$(uname -r)"
|
||||||
|
;;
|
||||||
OpenBSD* )
|
OpenBSD* )
|
||||||
host_os="openbsd$(uname -r)"
|
host_os="openbsd$(uname -r)"
|
||||||
;;
|
;;
|
||||||
|
|
6
test/init.bats
Normal file → Executable file
6
test/init.bats
Normal file → Executable file
|
@ -47,7 +47,7 @@ OUT
|
||||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||||
run pyenv-init - fish
|
run pyenv-init - fish
|
||||||
assert_success
|
assert_success
|
||||||
assert_line ". '${root}/test/../libexec/../completions/pyenv.fish'"
|
assert_line "source '${root}/test/../libexec/../completions/pyenv.fish'"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "fish instructions" {
|
@test "fish instructions" {
|
||||||
|
@ -73,7 +73,7 @@ OUT
|
||||||
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||||
run pyenv-init - fish
|
run pyenv-init - fish
|
||||||
assert_success
|
assert_success
|
||||||
assert_line 0 "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
|
assert_line 0 "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "can add shims to PATH more than once" {
|
@test "can add shims to PATH more than once" {
|
||||||
|
@ -87,7 +87,7 @@ OUT
|
||||||
export PATH="${PYENV_ROOT}/shims:$PATH"
|
export PATH="${PYENV_ROOT}/shims:$PATH"
|
||||||
run pyenv-init - fish
|
run pyenv-init - fish
|
||||||
assert_success
|
assert_success
|
||||||
assert_line 0 "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
|
assert_line 0 "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "outputs sh-compatible syntax" {
|
@test "outputs sh-compatible syntax" {
|
||||||
|
|
|
@ -20,14 +20,34 @@ load test_helper
|
||||||
assert_success 'echo "$PYENV_VERSION"'
|
assert_success 'echo "$PYENV_VERSION"'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "shell revert" {
|
||||||
|
PYENV_SHELL=bash run pyenv-sh-shell -
|
||||||
|
assert_success
|
||||||
|
assert_line 0 'if [ -n "${PYENV_VERSION_OLD+x}" ]; then'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "shell revert (fish)" {
|
||||||
|
PYENV_SHELL=fish run pyenv-sh-shell -
|
||||||
|
assert_success
|
||||||
|
assert_line 0 'if set -q PYENV_VERSION_OLD'
|
||||||
|
}
|
||||||
|
|
||||||
@test "shell unset" {
|
@test "shell unset" {
|
||||||
PYENV_SHELL=bash run pyenv-sh-shell --unset
|
PYENV_SHELL=bash run pyenv-sh-shell --unset
|
||||||
assert_success "unset PYENV_VERSION"
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
PYENV_VERSION_OLD="\$PYENV_VERSION"
|
||||||
|
unset PYENV_VERSION
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "shell unset (fish)" {
|
@test "shell unset (fish)" {
|
||||||
PYENV_SHELL=fish run pyenv-sh-shell --unset
|
PYENV_SHELL=fish run pyenv-sh-shell --unset
|
||||||
assert_success "set -e PYENV_VERSION"
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
||||||
|
set -e PYENV_VERSION
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "shell change invalid version" {
|
@test "shell change invalid version" {
|
||||||
|
@ -42,11 +62,19 @@ SH
|
||||||
@test "shell change version" {
|
@test "shell change version" {
|
||||||
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
||||||
PYENV_SHELL=bash run pyenv-sh-shell 1.2.3
|
PYENV_SHELL=bash run pyenv-sh-shell 1.2.3
|
||||||
assert_success 'export PYENV_VERSION="1.2.3"'
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
PYENV_VERSION_OLD="\$PYENV_VERSION"
|
||||||
|
export PYENV_VERSION="1.2.3"
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "shell change version (fish)" {
|
@test "shell change version (fish)" {
|
||||||
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
||||||
PYENV_SHELL=fish run pyenv-sh-shell 1.2.3
|
PYENV_SHELL=fish run pyenv-sh-shell 1.2.3
|
||||||
assert_success 'setenv PYENV_VERSION "1.2.3"'
|
assert_success
|
||||||
|
assert_output <<OUT
|
||||||
|
set -gu PYENV_VERSION_OLD "\$PYENV_VERSION"
|
||||||
|
set -gx PYENV_VERSION "1.2.3"
|
||||||
|
OUT
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue