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:
Daniel Hahler 2017-06-05 15:02:24 +02:00
commit 3fd23431af
7 changed files with 108 additions and 26 deletions

View file

@ -12,7 +12,7 @@
set -e
[ -n "$PYENV_DEBUG" ] && set -x
version="1.0.10"
version="1.1.0"
git_revision=""
if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q pyenv; then

View file

@ -86,8 +86,8 @@ mkdir -p "${PYENV_ROOT}/"{shims,versions}
case "$shell" in
fish )
echo "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
echo "setenv PYENV_SHELL $shell"
echo "set -gx PATH '${PYENV_ROOT}/shims' \$PATH"
echo "set -gx PYENV_SHELL $shell"
;;
* )
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
@ -97,10 +97,7 @@ esac
completion="${root}/completions/pyenv.${shell}"
if [ -r "$completion" ]; then
case "$shell" in
fish ) echo ". '$completion'" ;;
* ) echo "source '$completion'" ;;
esac
echo "source '$completion'"
fi
if [ -z "$no_rehash" ]; then
@ -117,7 +114,7 @@ function pyenv
switch "\$command"
case ${commands[*]}
. (pyenv "sh-\$command" \$argv|psub)
source (pyenv "sh-\$command" \$argv|psub)
case '*'
command pyenv "\$command" \$argv
end

View file

@ -2,7 +2,8 @@
#
# Summary: Set or show the shell-specific Python version
#
# Usage: pyenv shell <version>
# Usage: pyenv shell <version>...
# pyenv shell -
# pyenv shell --unset
#
# 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.
# The special version string `system' will use your default system Python.
# 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
[ -n "$PYENV_DEBUG" ] && set -x
@ -31,7 +37,7 @@ if [ -z "$versions" ]; then
echo "pyenv: no shell-specific version configured" >&2
exit 1
else
echo "echo \"\$PYENV_VERSION\""
echo 'echo "$PYENV_VERSION"'
exit
fi
fi
@ -39,28 +45,76 @@ fi
if [ "$versions" = "--unset" ]; then
case "$shell" in
fish )
echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"'
echo "set -e PYENV_VERSION"
;;
* )
echo 'PYENV_VERSION_OLD="$PYENV_VERSION"'
echo "unset PYENV_VERSION"
;;
esac
exit
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.
if pyenv-prefix "${versions[@]}" >/dev/null; then
OLDIFS="$IFS"
IFS=: version="${versions[*]}"
IFS="$OLDIFS"
case "$shell" in
fish )
echo "setenv PYENV_VERSION \"${version}\""
;;
* )
echo "export PYENV_VERSION=\"${version}\""
;;
esac
if [ "$version" != "$PYENV_VERSION" ]; then
case "$shell" in
fish )
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}\""
;;
esac
fi
else
echo "false"
exit 1

View file

@ -18,7 +18,7 @@ fi
remove_from_path() {
local path_to_remove="$1"
local path_before
local result=":$PATH:"
local result=":${PATH//\~/$HOME}:"
while [ "$path_before" != "$result" ]; do
path_before="$result"
result="${result//:$path_to_remove:/:}"

3
src/configure vendored
View file

@ -21,6 +21,9 @@ case "$(uname -s)" in
Darwin* )
host_os="darwin$(uname -r)"
;;
FreeBSD* )
host_os="freebsd$(uname -r)"
;;
OpenBSD* )
host_os="openbsd$(uname -r)"
;;

6
test/init.bats Normal file → Executable file
View file

@ -47,7 +47,7 @@ OUT
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
run pyenv-init - fish
assert_success
assert_line ". '${root}/test/../libexec/../completions/pyenv.fish'"
assert_line "source '${root}/test/../libexec/../completions/pyenv.fish'"
}
@test "fish instructions" {
@ -73,7 +73,7 @@ OUT
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
run pyenv-init - fish
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" {
@ -87,7 +87,7 @@ OUT
export PATH="${PYENV_ROOT}/shims:$PATH"
run pyenv-init - fish
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" {

View file

@ -20,14 +20,34 @@ load test_helper
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" {
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)" {
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" {
@ -42,11 +62,19 @@ SH
@test "shell change version" {
mkdir -p "${PYENV_ROOT}/versions/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)" {
mkdir -p "${PYENV_ROOT}/versions/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
}