Merge pull request #1133 from pyenv/rbenv-20180402

Import changes from rbenv as of 20180402
This commit is contained in:
Yamashita, Yuu 2018-04-05 16:47:20 +09:00 committed by GitHub
commit 35f7ef8708
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 57 additions and 34 deletions

View file

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
unset CDPATH
if [ "$1" = "--debug" ]; then if [ "$1" = "--debug" ]; then
export PYENV_DEBUG=1 export PYENV_DEBUG=1
@ -22,7 +21,8 @@ abort() {
if enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then if enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
abs_dirname() { abs_dirname() {
local path="$(realpath "$1")" local path
path="$(realpath "$1")"
echo "${path%/*}" echo "${path%/*}"
} }
else else
@ -69,6 +69,11 @@ if [ -z "${PYENV_DIR}" ]; then
export PYENV_DIR export PYENV_DIR
unset PYENV_FILE_ARG unset PYENV_FILE_ARG
fi fi
else
[[ $PYENV_DIR == /* ]] || PYENV_DIR="$PWD/$PYENV_DIR"
cd "$PYENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$PYENV_DIR'"
PYENV_DIR="$PWD"
cd "$OLDPWD"
fi fi
if [ -z "${PYENV_DIR}" ]; then if [ -z "${PYENV_DIR}" ]; then
@ -121,7 +126,13 @@ case "$command" in
;; ;;
* ) * )
command_path="$(command -v "pyenv-$command" || true)" command_path="$(command -v "pyenv-$command" || true)"
[ -n "$command_path" ] || abort "no such command \`$command'" if [ -z "$command_path" ]; then
if [ "$command" == "shell" ]; then
abort "shell integration not enabled. Run \`pyenv init' for instructions."
else
abort "no such command \`$command'"
fi
fi
shift 1 shift 1
if [ "$1" = --help ]; then if [ "$1" = --help ]; then

View file

@ -28,15 +28,15 @@ shopt -s nullglob
for command in "${path}/pyenv-"*; do for command in "${path}/pyenv-"*; do
command="${command##*pyenv-}" command="${command##*pyenv-}"
if [ -n "$sh" ]; then if [ -n "$sh" ]; then
if [ ${command:0:3} = "sh-" ]; then if [ "${command:0:3}" = "sh-" ]; then
echo ${command##sh-} echo "${command##sh-}"
fi fi
elif [ -n "$nosh" ]; then elif [ -n "$nosh" ]; then
if [ ${command:0:3} != "sh-" ]; then if [ "${command:0:3}" != "sh-" ]; then
echo ${command##sh-} echo "${command##sh-}"
fi fi
else else
echo ${command##sh-} echo "${command##sh-}"
fi fi
done done
done done

View file

@ -42,6 +42,7 @@ extract_initial_comment_block() {
} }
collect_documentation() { collect_documentation() {
# shellcheck disable=SC2016
$(type -p gawk awk | head -1) ' $(type -p gawk awk | head -1) '
/^Summary:/ { /^Summary:/ {
summary = substr($0, 10) summary = substr($0, 10)
@ -86,7 +87,8 @@ collect_documentation() {
} }
documentation_for() { documentation_for() {
local filename="$(command_path "$1")" local filename
filename="$(command_path "$1")"
if [ -n "$filename" ]; then if [ -n "$filename" ]; then
extract_initial_comment_block < "$filename" | collect_documentation extract_initial_comment_block < "$filename" | collect_documentation
fi fi
@ -114,7 +116,7 @@ print_help() {
eval "$(documentation_for "$command")" eval "$(documentation_for "$command")"
[ -n "$help" ] || help="$summary" [ -n "$help" ] || help="$summary"
if [ -n "$usage" -o -n "$summary" ]; then if [ -n "$usage" ] || [ -n "$summary" ]; then
if [ -n "$usage" ]; then if [ -n "$usage" ]; then
echo "$usage" echo "$usage"
else else

View file

@ -138,7 +138,7 @@ esac
if [ "$shell" != "fish" ]; then if [ "$shell" != "fish" ]; then
IFS="|" IFS="|"
cat <<EOS cat <<EOS
command="\$1" command="\${1:-}"
if [ "\$#" -gt 0 ]; then if [ "\$#" -gt 0 ]; then
shift shift
fi fi

View file

@ -16,7 +16,7 @@ mkdir -p "$SHIM_PATH"
# to stderr and exit with a non-zero status. # to stderr and exit with a non-zero status.
set -o noclobber set -o noclobber
{ echo > "$PROTOTYPE_SHIM_PATH" { echo > "$PROTOTYPE_SHIM_PATH"
} 2>/dev/null || } 2>| /dev/null ||
{ if [ -w "$SHIM_PATH" ]; then { if [ -w "$SHIM_PATH" ]; then
echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
else else
@ -83,7 +83,7 @@ remove_outdated_shims() {
list_executable_names() { list_executable_names() {
local version file local version file
pyenv-versions --bare --skip-aliases | \ pyenv-versions --bare --skip-aliases | \
while read version; do while read -r version; do
for file in "${PYENV_ROOT}/versions/${version}/bin/"*; do for file in "${PYENV_ROOT}/versions/${version}/bin/"*; do
echo "${file##*/}" echo "${file##*/}"
done done
@ -136,6 +136,7 @@ shopt -s nullglob
# executables. # executables.
create_prototype_shim create_prototype_shim
remove_outdated_shims remove_outdated_shims
# shellcheck disable=SC2046
make_shims $(list_executable_names | sort -u) make_shims $(list_executable_names | sort -u)

View file

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Summary: Display the root directory where versions and shims are kept # Summary: Display the root directory where versions and shims are kept
echo $PYENV_ROOT echo "$PYENV_ROOT"

View file

@ -20,7 +20,7 @@ fi
whence() { whence() {
local command="$1" local command="$1"
pyenv-versions --bare | while read version; do pyenv-versions --bare | while read -r version; do
path="$(pyenv-prefix "$version")/bin/${command}" path="$(pyenv-prefix "$version")/bin/${command}"
if [ -x "$path" ]; then if [ -x "$path" ]; then
[ "$print_paths" ] && echo "$path" || echo "$version" [ "$print_paths" ] && echo "$path" || echo "$version"

24
src/configure vendored
View file

@ -34,16 +34,16 @@ esac
eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")" eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")"
sed " sed "
s,@CC@,${CC}, s#@CC@#${CC}#
s,@CFLAGS@,${CFLAGS}, s#@CFLAGS@#${CFLAGS}#
s,@LOCAL_CFLAGS@,${LOCAL_CFLAGS}, s#@LOCAL_CFLAGS@#${LOCAL_CFLAGS}#
s,@DEFS@,${DEFS}, s#@DEFS@#${DEFS}#
s,@LOCAL_DEFS@,${LOCAL_DEFS}, s#@LOCAL_DEFS@#${LOCAL_DEFS}#
s,@SHOBJ_CC@,${SHOBJ_CC}, s#@SHOBJ_CC@#${SHOBJ_CC}#
s,@SHOBJ_CFLAGS@,${SHOBJ_CFLAGS}, s#@SHOBJ_CFLAGS@#${SHOBJ_CFLAGS}#
s,@SHOBJ_LD@,${SHOBJ_LD}, s#@SHOBJ_LD@#${SHOBJ_LD}#
s,@SHOBJ_LDFLAGS@,${SHOBJ_LDFLAGS//,/\\,}, s#@SHOBJ_LDFLAGS@#${SHOBJ_LDFLAGS}#
s,@SHOBJ_XLDFLAGS@,${SHOBJ_XLDFLAGS//,/\\,}, s#@SHOBJ_XLDFLAGS@#${SHOBJ_XLDFLAGS}#
s,@SHOBJ_LIBS@,${SHOBJ_LIBS}, s#@SHOBJ_LIBS@#${SHOBJ_LIBS}#
s,@SHOBJ_STATUS@,${SHOBJ_STATUS}, s#@SHOBJ_STATUS@#${SHOBJ_STATUS}#
" "$src_dir"/Makefile.in > "$src_dir"/Makefile " "$src_dir"/Makefile.in > "$src_dir"/Makefile

View file

@ -2,6 +2,17 @@
load test_helper load test_helper
@test "shell integration disabled" {
run pyenv shell
assert_failure "pyenv: shell integration not enabled. Run \`pyenv init' for instructions."
}
@test "shell integration enabled" {
eval "$(pyenv init -)"
run pyenv shell
assert_success "pyenv: no shell-specific version configured"
}
@test "no shell version" { @test "no shell version" {
mkdir -p "${PYENV_TEST_DIR}/myproject" mkdir -p "${PYENV_TEST_DIR}/myproject"
cd "${PYENV_TEST_DIR}/myproject" cd "${PYENV_TEST_DIR}/myproject"

View file

@ -9,7 +9,7 @@ setup() {
create_file() { create_file() {
mkdir -p "$(dirname "$1")" mkdir -p "$(dirname "$1")"
touch "$1" echo "system" > "$1"
} }
@test "detects global 'version' file" { @test "detects global 'version' file" {

View file

@ -26,7 +26,7 @@ setup() {
} }
@test "detects local file" { @test "detects local file" {
touch .python-version echo "system" > .python-version
run pyenv-version-origin run pyenv-version-origin
assert_success "${PWD}/.python-version" assert_success "${PWD}/.python-version"
} }

View file

@ -60,12 +60,11 @@ create_executable() {
} }
@test "doesn't include current directory in PATH search" { @test "doesn't include current directory in PATH search" {
export PATH="$(path_without "kill-all-humans")"
mkdir -p "$PYENV_TEST_DIR" mkdir -p "$PYENV_TEST_DIR"
cd "$PYENV_TEST_DIR" cd "$PYENV_TEST_DIR"
touch kill-all-humans touch kill-all-humans
chmod +x kill-all-humans chmod +x kill-all-humans
PYENV_VERSION=system run pyenv-which kill-all-humans PATH="$(path_without "kill-all-humans")" PYENV_VERSION=system run pyenv-which kill-all-humans
assert_failure "pyenv: kill-all-humans: command not found" assert_failure "pyenv: kill-all-humans: command not found"
} }
@ -91,9 +90,8 @@ OUT
} }
@test "no executable found for system version" { @test "no executable found for system version" {
export PATH="$(path_without "py.test")" PATH="$(path_without "rake")" PYENV_VERSION=system run pyenv-which rake
PYENV_VERSION=system run pyenv-which py.test assert_failure "pyenv: rake: command not found"
assert_failure "pyenv: py.test: command not found"
} }
@test "executable found in other versions" { @test "executable found in other versions" {