diff --git a/libexec/pyenv b/libexec/pyenv index a1266c1f..fbdd880c 100755 --- a/libexec/pyenv +++ b/libexec/pyenv @@ -1,6 +1,5 @@ #!/usr/bin/env bash set -e -unset CDPATH if [ "$1" = "--debug" ]; then export PYENV_DEBUG=1 @@ -22,7 +21,8 @@ abort() { if enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then abs_dirname() { - local path="$(realpath "$1")" + local path + path="$(realpath "$1")" echo "${path%/*}" } else @@ -69,6 +69,11 @@ if [ -z "${PYENV_DIR}" ]; then export PYENV_DIR unset PYENV_FILE_ARG 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 if [ -z "${PYENV_DIR}" ]; then @@ -121,7 +126,13 @@ case "$command" in ;; * ) 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 if [ "$1" = --help ]; then diff --git a/libexec/pyenv-commands b/libexec/pyenv-commands index 547fd265..283ce44b 100755 --- a/libexec/pyenv-commands +++ b/libexec/pyenv-commands @@ -28,15 +28,15 @@ shopt -s nullglob for command in "${path}/pyenv-"*; do command="${command##*pyenv-}" if [ -n "$sh" ]; then - if [ ${command:0:3} = "sh-" ]; then - echo ${command##sh-} + if [ "${command:0:3}" = "sh-" ]; then + echo "${command##sh-}" fi elif [ -n "$nosh" ]; then - if [ ${command:0:3} != "sh-" ]; then - echo ${command##sh-} + if [ "${command:0:3}" != "sh-" ]; then + echo "${command##sh-}" fi else - echo ${command##sh-} + echo "${command##sh-}" fi done done diff --git a/libexec/pyenv-help b/libexec/pyenv-help index a63bd7d6..8270993e 100755 --- a/libexec/pyenv-help +++ b/libexec/pyenv-help @@ -42,6 +42,7 @@ extract_initial_comment_block() { } collect_documentation() { + # shellcheck disable=SC2016 $(type -p gawk awk | head -1) ' /^Summary:/ { summary = substr($0, 10) @@ -86,7 +87,8 @@ collect_documentation() { } documentation_for() { - local filename="$(command_path "$1")" + local filename + filename="$(command_path "$1")" if [ -n "$filename" ]; then extract_initial_comment_block < "$filename" | collect_documentation fi @@ -114,7 +116,7 @@ print_help() { eval "$(documentation_for "$command")" [ -n "$help" ] || help="$summary" - if [ -n "$usage" -o -n "$summary" ]; then + if [ -n "$usage" ] || [ -n "$summary" ]; then if [ -n "$usage" ]; then echo "$usage" else diff --git a/libexec/pyenv-init b/libexec/pyenv-init index df196295..659d1f4c 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -138,7 +138,7 @@ esac if [ "$shell" != "fish" ]; then IFS="|" cat < "$PROTOTYPE_SHIM_PATH" -} 2>/dev/null || +} 2>| /dev/null || { if [ -w "$SHIM_PATH" ]; then echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" else @@ -83,7 +83,7 @@ remove_outdated_shims() { list_executable_names() { local version file pyenv-versions --bare --skip-aliases | \ - while read version; do + while read -r version; do for file in "${PYENV_ROOT}/versions/${version}/bin/"*; do echo "${file##*/}" done @@ -136,6 +136,7 @@ shopt -s nullglob # executables. create_prototype_shim remove_outdated_shims +# shellcheck disable=SC2046 make_shims $(list_executable_names | sort -u) diff --git a/libexec/pyenv-root b/libexec/pyenv-root index 6669caa2..b4a135f3 100755 --- a/libexec/pyenv-root +++ b/libexec/pyenv-root @@ -1,3 +1,3 @@ #!/usr/bin/env bash # Summary: Display the root directory where versions and shims are kept -echo $PYENV_ROOT +echo "$PYENV_ROOT" diff --git a/libexec/pyenv-whence b/libexec/pyenv-whence index d551e567..fddcf112 100755 --- a/libexec/pyenv-whence +++ b/libexec/pyenv-whence @@ -20,7 +20,7 @@ fi whence() { local command="$1" - pyenv-versions --bare | while read version; do + pyenv-versions --bare | while read -r version; do path="$(pyenv-prefix "$version")/bin/${command}" if [ -x "$path" ]; then [ "$print_paths" ] && echo "$path" || echo "$version" diff --git a/src/configure b/src/configure index 10d0ff57..54b33798 100755 --- a/src/configure +++ b/src/configure @@ -34,16 +34,16 @@ esac eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")" sed " - s,@CC@,${CC}, - s,@CFLAGS@,${CFLAGS}, - s,@LOCAL_CFLAGS@,${LOCAL_CFLAGS}, - s,@DEFS@,${DEFS}, - s,@LOCAL_DEFS@,${LOCAL_DEFS}, - s,@SHOBJ_CC@,${SHOBJ_CC}, - s,@SHOBJ_CFLAGS@,${SHOBJ_CFLAGS}, - s,@SHOBJ_LD@,${SHOBJ_LD}, - s,@SHOBJ_LDFLAGS@,${SHOBJ_LDFLAGS//,/\\,}, - s,@SHOBJ_XLDFLAGS@,${SHOBJ_XLDFLAGS//,/\\,}, - s,@SHOBJ_LIBS@,${SHOBJ_LIBS}, - s,@SHOBJ_STATUS@,${SHOBJ_STATUS}, + s#@CC@#${CC}# + s#@CFLAGS@#${CFLAGS}# + s#@LOCAL_CFLAGS@#${LOCAL_CFLAGS}# + s#@DEFS@#${DEFS}# + s#@LOCAL_DEFS@#${LOCAL_DEFS}# + s#@SHOBJ_CC@#${SHOBJ_CC}# + s#@SHOBJ_CFLAGS@#${SHOBJ_CFLAGS}# + s#@SHOBJ_LD@#${SHOBJ_LD}# + s#@SHOBJ_LDFLAGS@#${SHOBJ_LDFLAGS}# + s#@SHOBJ_XLDFLAGS@#${SHOBJ_XLDFLAGS}# + s#@SHOBJ_LIBS@#${SHOBJ_LIBS}# + s#@SHOBJ_STATUS@#${SHOBJ_STATUS}# " "$src_dir"/Makefile.in > "$src_dir"/Makefile diff --git a/test/shell.bats b/test/shell.bats index 82383aad..0871065c 100644 --- a/test/shell.bats +++ b/test/shell.bats @@ -2,6 +2,17 @@ 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" { mkdir -p "${PYENV_TEST_DIR}/myproject" cd "${PYENV_TEST_DIR}/myproject" diff --git a/test/version-file.bats b/test/version-file.bats index 84ceba5d..c46fb389 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -9,7 +9,7 @@ setup() { create_file() { mkdir -p "$(dirname "$1")" - touch "$1" + echo "system" > "$1" } @test "detects global 'version' file" { diff --git a/test/version-origin.bats b/test/version-origin.bats index be6d6f93..cd7ec563 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -26,7 +26,7 @@ setup() { } @test "detects local file" { - touch .python-version + echo "system" > .python-version run pyenv-version-origin assert_success "${PWD}/.python-version" } diff --git a/test/which.bats b/test/which.bats index 5dd10164..5145cdb4 100644 --- a/test/which.bats +++ b/test/which.bats @@ -60,12 +60,11 @@ create_executable() { } @test "doesn't include current directory in PATH search" { - export PATH="$(path_without "kill-all-humans")" mkdir -p "$PYENV_TEST_DIR" cd "$PYENV_TEST_DIR" touch 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" } @@ -91,9 +90,8 @@ OUT } @test "no executable found for system version" { - export PATH="$(path_without "py.test")" - PYENV_VERSION=system run pyenv-which py.test - assert_failure "pyenv: py.test: command not found" + PATH="$(path_without "rake")" PYENV_VERSION=system run pyenv-which rake + assert_failure "pyenv: rake: command not found" } @test "executable found in other versions" {