Merge remote-tracking branch 'rbenv/master' into rbenv-20151121

This commit is contained in:
Yamashita, Yuu 2015-11-21 04:13:52 +00:00
commit 8da3749648
24 changed files with 309 additions and 111 deletions

2
.gitignore vendored
View file

@ -6,4 +6,4 @@
/libexec/*.dylib /libexec/*.dylib
/src/Makefile /src/Makefile
/src/*.o /src/*.o
bats/ /bats/

View file

@ -257,6 +257,31 @@ To upgrade to a specific release of pyenv, check out the corresponding tag:
v0.1.0 v0.1.0
$ git checkout v0.1.0 $ git checkout v0.1.0
### Uninstalling pyenv
The simplicity of pyenv makes it easy to temporarily disable it, or
uninstall from the system.
1. To **disable** pyenv managing your Python versions, simply remove the
`pyenv init` line from your shell startup configuration. This will
remove pyenv shims directory from PATH, and future invocations like
`python` will execute the system Python version, as before pyenv.
`pyenv` will still be accessible on the command line, but your Python
apps won't be affected by version switching.
2. To completely **uninstall** pyenv, perform step (1) and then remove
its root directory. This will **delete all Python versions** that were
installed under `` `pyenv root`/versions/ `` directory:
rm -rf `pyenv root`
If you've installed pyenv using a package manager, as a final step
perform the pyenv package removal. For instance, for Homebrew:
brew uninstall pyenv
## Command Reference
### Homebrew on Mac OS X ### Homebrew on Mac OS X
@ -328,43 +353,32 @@ See [COMMANDS.md](COMMANDS.md).
---- ----
## Environment variables
You can affect how pyenv operates with the following settings:
name | default | description
-----|---------|------------
`PYENV_VERSION` | | Specifies the Python version to be used.<br>Also see [`pyenv shell`](#pyenv-shell)
`PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.<br>Also see `pyenv root`
`PYENV_DEBUG` | | Outputs debug information.<br>Also as: `pyenv --debug <subcommand>`
`PYENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for pyenv hooks.
`PYENV_DIR` | `$PWD` | Directory to start searching for `.python-version` files.
## Development ## Development
The pyenv source code is [hosted on GitHub](https://github.com/yyuu/pyenv). The pyenv source code is [hosted on
It's clean, modular, and easy to understand--even if you're not a shell hacker. GitHub](https://github.com/yyuu/pyenv). It's clean, modular,
and easy to understand, even if you're not a shell hacker.
Please feel free to submit Pull Requests and report bugs on the Tests are executed using [Bats](https://github.com/sstephenson/bats):
[issue tracker](https://github.com/yyuu/pyenv/issues).
$ bats test
$ bats/test/<file>.bats
Please feel free to submit pull requests and file bugs on the [issue
tracker](https://github.com/yyuu/pyenv/issues).
### Version History [pyenv-virtualenv]: https://github.com/yyuu/pyenv-virtualenv#readme
[hooks]: https://github.com/yyuu/pyenv/wiki/Authoring-plugins#pyenv-hooks
See [CHANGELOG.md](CHANGELOG.md).
### License
(The MIT license)
* Copyright (c) 2013 Yamashita, Yuu
* Copyright (c) 2013 Sam Stephenson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -12,21 +12,24 @@ if [ -n "$PYENV_DEBUG" ]; then
set -x set -x
fi fi
if enable -f "${0%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then abort() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "pyenv: $*"
fi
} >&2
exit 1
}
if enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
abs_dirname() { abs_dirname() {
local path="$(realpath "$1")" local path="$(realpath "$1")"
echo "${path%/*}" echo "${path%/*}"
} }
else else
if [ -n "$PYENV_NATIVE_EXT" ]; then [ -z "$PYENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin"
echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1) READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then [ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?"
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() { resolve_link() {
$READLINK "$1" $READLINK "$1"
@ -70,10 +73,7 @@ fi
if [ -z "${PYENV_DIR}" ]; then if [ -z "${PYENV_DIR}" ]; then
PYENV_DIR="$(pwd)" PYENV_DIR="$(pwd)"
else else
cd "$PYENV_DIR" 2>/dev/null || { cd "$PYENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$PYENV_DIR'"
echo "pyenv: cannot change working directory to \`$PYENV_DIR'"
exit 1
} >&2
PYENV_DIR="$(pwd)" PYENV_DIR="$(pwd)"
cd "$OLDPWD" cd "$OLDPWD"
fi fi
@ -104,20 +104,26 @@ shopt -u nullglob
command="$1" command="$1"
case "$command" in case "$command" in
"" | "-h" | "--help" ) "" )
echo -e "$(pyenv---version)\n$(pyenv-help)" >&2 { pyenv---version
pyenv-help
} | abort
;; ;;
"-v" ) -v | --version )
exec pyenv---version exec pyenv---version
;; ;;
-h | --help )
exec pyenv-help
;;
* ) * )
command_path="$(command -v "pyenv-$command" || true)" command_path="$(command -v "pyenv-$command" || true)"
if [ -z "$command_path" ]; then [ -n "$command_path" ] || abort "no such command \`$command'"
echo "pyenv: no such command \`$command'" >&2
exit 1
fi
shift 1 shift 1
if [ "$1" = --help ]; then
exec pyenv-help "$command"
else
exec "$command_path" "$@" exec "$command_path" "$@"
fi
;; ;;
esac esac

View file

@ -13,10 +13,14 @@ set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
version="20151105" version="20151105"
git_revision=""
if cd "$PYENV_ROOT" 2>/dev/null; then for source_dir in "${BASH_SOURCE%/*}" "$PYENV_ROOT"; do
if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q pyenv; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)" git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}" git_revision="${git_revision#v}"
fi [ -z "$git_revision" ] || break
fi
done
echo "pyenv ${git_revision:-$version}" echo "pyenv ${git_revision:-$version}"

View file

@ -10,7 +10,16 @@ if [ -z "$COMMAND" ]; then
exit 1 exit 1
fi fi
# Provide pyenv completions
if [ "$COMMAND" = "--complete" ]; then
exec pyenv-commands
fi
COMMAND_PATH="$(command -v "pyenv-$COMMAND" || command -v "pyenv-sh-$COMMAND")" COMMAND_PATH="$(command -v "pyenv-$COMMAND" || command -v "pyenv-sh-$COMMAND")"
# --help is provided automatically
echo --help
if grep -iE "^([#%]|--|//) provide pyenv completions" "$COMMAND_PATH" >/dev/null; then if grep -iE "^([#%]|--|//) provide pyenv completions" "$COMMAND_PATH" >/dev/null; then
shift shift
exec "$COMMAND_PATH" --complete "$@" exec "$COMMAND_PATH" --complete "$@"

View file

@ -15,6 +15,12 @@
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --usage
exec pyenv-commands
fi
command_path() { command_path() {
local command="$1" local command="$1"
command -v pyenv-"$command" || command -v pyenv-sh-"$command" || true command -v pyenv-"$command" || command -v pyenv-sh-"$command" || true

View file

@ -35,16 +35,17 @@ resolve_link() {
} }
realpath() { realpath() {
local cwd="$(pwd)" local cwd="$PWD"
local path="$1" local path="$1"
local name
while [ -n "$path" ]; do while [ -n "$path" ]; do
cd "${path%/*}" name="${path##*/}"
local name="${path##*/}" [ "$name" = "$path" ] || cd "${path%/*}"
path="$(resolve_link "$name" || true)" path="$(resolve_link "$name" || true)"
done done
echo "$(pwd)/$name" echo "${PWD}/$name"
cd "$cwd" cd "$cwd"
} }
fi fi

View file

@ -5,6 +5,17 @@
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo -
echo --no-rehash
echo bash
echo fish
echo ksh
echo zsh
exit
fi
print="" print=""
no_rehash="" no_rehash=""
for args in "$@" for args in "$@"
@ -25,7 +36,8 @@ if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}" shell="${shell##-}"
shell="${shell%% *}" shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")" shell="${shell:-$SHELL}"
shell="${shell##*/}"
fi fi
root="${0%/*}/.." root="${0%/*}/.."
@ -33,7 +45,11 @@ root="${0%/*}/.."
if [ -z "$print" ]; then if [ -z "$print" ]; then
case "$shell" in case "$shell" in
bash ) bash )
if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then
profile='~/.bashrc'
else
profile='~/.bash_profile' profile='~/.bash_profile'
fi
;; ;;
zsh ) zsh )
profile='~/.zshrc' profile='~/.zshrc'
@ -49,8 +65,8 @@ if [ -z "$print" ]; then
;; ;;
esac esac
{ echo "# Load pyenv automatically by adding" { echo "# Load pyenv automatically by appending"
echo "# the following to the end of ${profile}:" echo "# the following to ${profile}:"
echo echo
case "$shell" in case "$shell" in
fish ) fish )
@ -88,7 +104,7 @@ if [ -r "$completion" ]; then
fi fi
if [ -z "$no_rehash" ]; then if [ -z "$no_rehash" ]; then
echo 'pyenv rehash 2>/dev/null' echo 'command pyenv rehash 2>/dev/null'
fi fi
commands=(`pyenv-commands --sh`) commands=(`pyenv-commands --sh`)
@ -101,7 +117,7 @@ function pyenv
switch "\$command" switch "\$command"
case ${commands[*]} case ${commands[*]}
eval (pyenv "sh-\$command" \$argv) . (pyenv "sh-\$command" \$argv|psub)
case '*' case '*'
command pyenv "\$command" \$argv command pyenv "\$command" \$argv
end end
@ -132,7 +148,7 @@ cat <<EOS
case "\$command" in case "\$command" in
${commands[*]}) ${commands[*]})
eval "\`pyenv "sh-\$command" "\$@"\`";; eval "\$(pyenv "sh-\$command" "\$@")";;
*) *)
command pyenv "\$command" "\$@";; command pyenv "\$command" "\$@";;
esac esac

View file

@ -81,10 +81,13 @@ remove_outdated_shims() {
# List basenames of executables for every Python version # List basenames of executables for every Python version
list_executable_names() { list_executable_names() {
local file local version file
for file in "$PYENV_ROOT"/versions/*/bin/*; do pyenv-versions --bare --skip-aliases | \
while read version; do
for file in "${PYENV_ROOT}/versions/${version}/bin/"*; do
echo "${file##*/}" echo "${file##*/}"
done done
done
} }
# The basename of each argument passed to `make_shims` will be # The basename of each argument passed to `make_shims` will be
@ -110,7 +113,7 @@ install_registered_shims() {
local shim file local shim file
for shim in $registered_shims; do for shim in $registered_shims; do
file="${SHIM_PATH}/${shim}" file="${SHIM_PATH}/${shim}"
[ -e "$file" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file" [ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
done done
} }

View file

@ -5,7 +5,8 @@ set -e
find_local_version_file() { find_local_version_file() {
local root="$1" local root="$1"
while [ -n "$root" ]; do while true; do
[[ "$root" =~ ^//[^/]*$ ]] && break
if [ -e "${root}/.python-version" ]; then if [ -e "${root}/.python-version" ]; then
echo "${root}/.python-version" echo "${root}/.python-version"
exit exit
@ -13,7 +14,7 @@ find_local_version_file() {
echo "${root}/.pyenv-version" echo "${root}/.pyenv-version"
exit exit
fi fi
[ "${root}" = "${root%/*}" ] && break [ -n "$root" ] || break
root="${root%/*}" root="${root%/*}"
done done
} }

View file

@ -28,7 +28,7 @@ OLDIFS="$IFS"
elif version_exists "${version#python-}"; then elif version_exists "${version#python-}"; then
versions=("${versions[@]}" "${version#python-}") versions=("${versions[@]}" "${version#python-}")
else else
echo "pyenv: version \`$version' is not installed" >&2 echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
any_not_installed=1 any_not_installed=1
fi fi
done done

View file

@ -1,13 +1,69 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Summary: List all Python versions available to pyenv # Summary: List all Python versions available to pyenv
# Usage: pyenv versions [--bare] # Usage: pyenv versions [--bare] [--skip-aliases]
# #
# Lists all Python versions found in `$PYENV_ROOT/versions/*'. # Lists all Python versions found in `$PYENV_ROOT/versions/*'.
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
if [ "$1" = "--bare" ]; then unset bare
unset skip_aliases
# Provide pyenv completions
for arg; do
case "$arg" in
--complete )
echo --bare
echo --skip-aliases
exit ;;
--bare ) bare=1 ;;
--skip-aliases ) skip_aliases=1 ;;
* )
pyenv-help --usage versions >&2
exit 1
;;
esac
done
versions_dir="${PYENV_ROOT}/versions"
if ! enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() {
$READLINK "$1"
}
realpath() {
local cwd="$PWD"
local path="$1"
local name
while [ -n "$path" ]; do
name="${path##*/}"
[ "$name" = "$path" ] || cd "${path%/*}"
path="$(resolve_link "$name" || true)"
done
echo "${PWD}/$name"
cd "$cwd"
}
fi
if [ -d "$versions_dir" ]; then
versions_dir="$(realpath "$versions_dir")"
fi
if [ -n "$bare" ]; then
hit_prefix="" hit_prefix=""
miss_prefix="" miss_prefix=""
current_versions=() current_versions=()
@ -50,8 +106,12 @@ if [ -n "$include_system" ] && PYENV_VERSION=system pyenv-which python >/dev/nul
fi fi
shopt -s nullglob shopt -s nullglob
for path in "${PYENV_ROOT}/versions/"*; do for path in "$versions_dir"/*; do
if [ -d "$path" ]; then if [ -d "$path" ]; then
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
target="$(realpath "$path")"
[ "${target%/*}" != "$versions_dir" ] || continue
fi
print_version "${path##*/}" print_version "${path##*/}"
# virtual environments created by anaconda/miniconda # virtual environments created by anaconda/miniconda
for env_path in "${path}/envs/"*; do for env_path in "${path}/envs/"*; do

View file

@ -58,6 +58,9 @@ done
if [ -x "$PYENV_COMMAND_PATH" ]; then if [ -x "$PYENV_COMMAND_PATH" ]; then
echo "$PYENV_COMMAND_PATH" echo "$PYENV_COMMAND_PATH"
elif [ "$PYENV_VERSION" != "system" ] && [ ! -d "${PYENV_ROOT}/versions/${PYENV_VERSION}" ]; then
echo "pyenv: version \`$PYENV_VERSION' is not installed (set by $(pyenv-version-origin))" >&2
exit 1
else else
any_not_installed=0 any_not_installed=0
for version in "${versions[@]}"; do for version in "${versions[@]}"; do

View file

@ -6,6 +6,18 @@ setup() {
mkdir -p "$HOME" mkdir -p "$HOME"
git config --global user.name "Tester" git config --global user.name "Tester"
git config --global user.email "tester@test.local" git config --global user.email "tester@test.local"
mkdir -p "${PYENV_TEST_DIR}/bin"
cat > "${PYENV_TEST_DIR}/bin/git" <<CMD
#!$BASH
if [[ \$1 == remote && \$PWD != "\$PYENV_TEST_DIR"/* ]]; then
echo "not allowed" >&2
exit 1
else
exec $(which git) "\$@"
fi
CMD
chmod +x "${PYENV_TEST_DIR}/bin/git"
} }
git_commit() { git_commit() {
@ -19,10 +31,25 @@ git_commit() {
[[ $output == "pyenv 20"* ]] [[ $output == "pyenv 20"* ]]
} }
@test "doesn't read version from non-pyenv repo" {
mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT"
git init
git remote add origin https://github.com/homebrew/homebrew.git
git_commit
git tag v1.0
cd "$PYENV_TEST_DIR"
run pyenv---version
assert_success
[[ $output == "pyenv 20"* ]]
}
@test "reads version from git repo" { @test "reads version from git repo" {
mkdir -p "$PYENV_ROOT" mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT" cd "$PYENV_ROOT"
git init git init
git remote add origin https://github.com/yyuu/pyenv.git
git_commit git_commit
git tag v20380119 git tag v20380119
git_commit git_commit
@ -38,6 +65,7 @@ git_commit() {
mkdir -p "$PYENV_ROOT" mkdir -p "$PYENV_ROOT"
cd "$PYENV_ROOT" cd "$PYENV_ROOT"
git init git init
git remote add origin https://github.com/yyuu/pyenv.git
git_commit git_commit
cd "$PYENV_TEST_DIR" cd "$PYENV_TEST_DIR"

View file

@ -13,7 +13,7 @@ create_command() {
create_command "pyenv-hello" "#!$BASH create_command "pyenv-hello" "#!$BASH
echo hello" echo hello"
run pyenv-completions hello run pyenv-completions hello
assert_success "" assert_success "--help"
} }
@test "command with completion support" { @test "command with completion support" {
@ -25,7 +25,11 @@ else
exit 1 exit 1
fi" fi"
run pyenv-completions hello run pyenv-completions hello
assert_success "hello" assert_success
assert_output <<OUT
--help
hello
OUT
} }
@test "forwards extra arguments" { @test "forwards extra arguments" {
@ -40,6 +44,7 @@ fi"
run pyenv-completions hello happy world run pyenv-completions hello happy world
assert_success assert_success
assert_output <<OUT assert_output <<OUT
--help
happy happy
world world
OUT OUT

View file

@ -16,8 +16,16 @@ create_executable() {
@test "fails with invalid version" { @test "fails with invalid version" {
export PYENV_VERSION="3.4" export PYENV_VERSION="3.4"
run pyenv-exec python -v run pyenv-exec python -V
assert_failure "pyenv: version \`3.4' is not installed" assert_failure "pyenv: version \`3.4' is not installed (set by PYENV_VERSION environment variable)"
}
@test "fails with invalid version set from file" {
mkdir -p "$PYENV_TEST_DIR"
cd "$PYENV_TEST_DIR"
echo 2.7 > .python-version
run pyenv-exec rspec
assert_failure "pyenv: version \`2.7' is not installed (set by $PWD/.python-version)"
} }
@test "completes with names of executables" { @test "completes with names of executables" {
@ -29,6 +37,7 @@ create_executable() {
run pyenv-completions exec run pyenv-completions exec
assert_success assert_success
assert_output <<OUT assert_output <<OUT
--help
fab fab
python python
OUT OUT

View file

@ -59,7 +59,13 @@ OUT
mkdir -p "$HOME" mkdir -p "$HOME"
touch "${HOME}/hola.bash" touch "${HOME}/hola.bash"
ln -s "../../home/hola.bash" "${path}/exec/hello.bash" ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
touch "${path}/exec/bright.sh"
ln -s "bright.sh" "${path}/exec/world.bash"
PYENV_HOOK_PATH="$path" run pyenv-hooks exec PYENV_HOOK_PATH="$path" run pyenv-hooks exec
assert_success "${HOME}/hola.bash" assert_success
assert_output <<OUT
${HOME}/hola.bash
${PYENV_TEST_DIR}/pyenv.d/exec/bright.sh
OUT
} }

View file

@ -14,7 +14,7 @@ load test_helper
@test "auto rehash" { @test "auto rehash" {
run pyenv-init - run pyenv-init -
assert_success assert_success
assert_line "pyenv rehash 2>/dev/null" assert_line "command pyenv rehash 2>/dev/null"
} }
@test "setup shell completions" { @test "setup shell completions" {

View file

@ -4,8 +4,8 @@ load test_helper
@test "blank invocation" { @test "blank invocation" {
run pyenv run pyenv
assert_success assert_failure
assert [ "${lines[0]}" == "pyenv 20151105" ] assert_line 0 "$(pyenv---version)"
} }
@test "invalid command" { @test "invalid command" {

View file

@ -1,18 +1,20 @@
unset PYENV_VERSION unset PYENV_VERSION
unset PYENV_DIR unset PYENV_DIR
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then # guard against executing this block twice due to bats internals
PYENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/pyenv" if [ -z "$PYENV_TEST_DIR" ]; then
else PYENV_TEST_DIR="${BATS_TMPDIR}/pyenv"
export PYENV_TEST_DIR="$(mktemp -d "${PYENV_TEST_DIR}.XXX" 2>/dev/null || echo "$PYENV_TEST_DIR")"
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
export PYENV_TEST_DIR="$(realpath "$PYENV_TEST_DIR")"
else
if [ -n "$PYENV_NATIVE_EXT" ]; then if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2 echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1 exit 1
fi fi
PYENV_TEST_DIR="${BATS_TMPDIR}/pyenv" fi
fi
# guard against executing this block twice due to bats internals
if [ "$PYENV_ROOT" != "${PYENV_TEST_DIR}/root" ]; then
export PYENV_ROOT="${PYENV_TEST_DIR}/root" export PYENV_ROOT="${PYENV_TEST_DIR}/root"
export HOME="${PYENV_TEST_DIR}/home" export HOME="${PYENV_TEST_DIR}/home"
@ -22,6 +24,9 @@ if [ "$PYENV_ROOT" != "${PYENV_TEST_DIR}/root" ]; then
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
PATH="${PYENV_ROOT}/shims:$PATH" PATH="${PYENV_ROOT}/shims:$PATH"
export PATH export PATH
for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done
unset xdg_var
fi fi
teardown() { teardown() {
@ -106,7 +111,7 @@ assert() {
# but in which system utils necessary for pyenv operation are still available. # but in which system utils necessary for pyenv operation are still available.
path_without() { path_without() {
local exe="$1" local exe="$1"
local path="${PATH}:" local path=":${PATH}:"
local found alt util local found alt util
for found in $(which -a "$exe"); do for found in $(which -a "$exe"); do
found="${found%/*}" found="${found%/*}"
@ -118,8 +123,9 @@ path_without() {
ln -s "${found}/$util" "${alt}/$util" ln -s "${found}/$util" "${alt}/$util"
fi fi
done done
path="${path/${found}:/${alt}:}" path="${path/:${found}:/:${alt}:}"
fi fi
done done
path="${path#:}"
echo "${path%:}" echo "${path%:}"
} }

View file

@ -49,7 +49,7 @@ setup() {
@test "missing version" { @test "missing version" {
PYENV_VERSION=1.2 run pyenv-version-name PYENV_VERSION=1.2 run pyenv-version-name
assert_failure "pyenv: version \`1.2' is not installed" assert_failure "pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)"
} }
@test "one missing version (second missing)" { @test "one missing version (second missing)" {
@ -57,7 +57,7 @@ setup() {
PYENV_VERSION="3.4.2:1.2" run pyenv-version-name PYENV_VERSION="3.4.2:1.2" run pyenv-version-name
assert_failure assert_failure
assert_output <<OUT assert_output <<OUT
pyenv: version \`1.2' is not installed pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.4.2 3.4.2
OUT OUT
} }
@ -67,7 +67,7 @@ OUT
PYENV_VERSION="1.2:3.4.2" run pyenv-version-name PYENV_VERSION="1.2:3.4.2" run pyenv-version-name
assert_failure assert_failure
assert_output <<OUT assert_output <<OUT
pyenv: version \`1.2' is not installed pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.4.2 3.4.2
OUT OUT
} }

View file

@ -42,7 +42,7 @@ setup() {
PYENV_VERSION=3.3.3:1.2 run pyenv-version PYENV_VERSION=3.3.3:1.2 run pyenv-version
assert_failure assert_failure
assert_output <<OUT assert_output <<OUT
pyenv: version \`1.2' is not installed pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.3.3 (set by PYENV_VERSION environment variable) 3.3.3 (set by PYENV_VERSION environment variable)
OUT OUT
} }
@ -52,8 +52,8 @@ OUT
PYENV_VERSION=3.4.2:3.3.3:1.2 run pyenv-version PYENV_VERSION=3.4.2:3.3.3:1.2 run pyenv-version
assert_failure assert_failure
assert_output <<OUT assert_output <<OUT
pyenv: version \`3.4.2' is not installed pyenv: version \`3.4.2' is not installed (set by PYENV_VERSION environment variable)
pyenv: version \`1.2' is not installed pyenv: version \`1.2' is not installed (set by PYENV_VERSION environment variable)
3.3.3 (set by PYENV_VERSION environment variable) 3.3.3 (set by PYENV_VERSION environment variable)
OUT OUT
} }

View file

@ -139,3 +139,18 @@ OUT
2.7.8 2.7.8
OUT OUT
} }
@test "doesn't list symlink aliases when --skip-aliases" {
create_version "1.8.7"
ln -s "1.8.7" "${PYENV_ROOT}/versions/1.8"
mkdir moo
ln -s "${PWD}/moo" "${PYENV_ROOT}/versions/1.9"
run pyenv-versions --bare --skip-aliases
assert_success
assert_output <<OUT
1.8.7
1.9
OUT
}

View file

@ -62,15 +62,15 @@ create_executable() {
@test "version not installed" { @test "version not installed" {
create_executable "3.4" "py.test" create_executable "3.4" "py.test"
PYENV_VERSION=3.3 run pyenv-which py.test PYENV_VERSION=3.3 run pyenv-which py.test
assert_failure "pyenv: version \`3.3' is not installed" assert_failure "pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)"
} }
@test "versions not installed" { @test "versions not installed" {
create_executable "3.4" "py.test" create_executable "3.4" "py.test"
PYENV_VERSION=2.7:3.3 run pyenv-which py.test PYENV_VERSION=2.7:3.3 run pyenv-which py.test
assert_failure <<OUT assert_failure <<OUT
pyenv: version \`2.7' is not installed pyenv: version \`2.7' is not installed (set by PYENV_VERSION environment variable)
pyenv: version \`3.3' is not installed pyenv: version \`3.3' is not installed (set by PYENV_VERSION environment variable)
OUT OUT
} }
@ -80,6 +80,12 @@ OUT
assert_failure "pyenv: fab: command not found" assert_failure "pyenv: fab: command not found"
} }
@test "no executable found for system version" {
export PATH="$(path_without "rake")"
PYENV_VERSION=system run pyenv-which rake
assert_failure "pyenv: rake: command not found"
}
@test "executable found in other versions" { @test "executable found in other versions" {
create_executable "2.7" "python" create_executable "2.7" "python"
create_executable "3.3" "py.test" create_executable "3.3" "py.test"