diff --git a/bin/python-local-exec b/bin/python-local-exec index a3068f67..62e59328 100755 --- a/bin/python-local-exec +++ b/bin/python-local-exec @@ -13,4 +13,11 @@ set -e export PYENV_DIR="${1%/*}" + +[ -n "$PYENV_SILENCE_WARNINGS" ] || { + echo "pyenv: \`python-local-exec' is deprecated and will be removed in the next release." + echo " To upgrade: https://github.com/yyuu/pyenv/wiki/python-local-exec" + echo +} >&2 + exec python "$@" diff --git a/completions/pyenv.bash b/completions/pyenv.bash index cd6ddb1c..c8d8aa6c 100644 --- a/completions/pyenv.bash +++ b/completions/pyenv.bash @@ -5,8 +5,10 @@ _pyenv() { if [ "$COMP_CWORD" -eq 1 ]; then COMPREPLY=( $(compgen -W "$(pyenv commands)" -- "$word") ) else - local command="${COMP_WORDS[1]}" - local completions="$(pyenv completions "$command")" + local words=("${COMP_WORDS[@]}") + unset words[0] + unset words[$COMP_CWORD] + local completions=$(pyenv completions "${words[@]}") COMPREPLY=( $(compgen -W "$completions" -- "$word") ) fi } diff --git a/completions/pyenv.zsh b/completions/pyenv.zsh index f27cdbbc..75b977b9 100644 --- a/completions/pyenv.zsh +++ b/completions/pyenv.zsh @@ -5,14 +5,13 @@ fi compctl -K _pyenv pyenv _pyenv() { - local word words completions + local words completions read -cA words - word="${words[2]}" if [ "${#words}" -eq 2 ]; then completions="$(pyenv commands)" else - completions="$(pyenv completions "${word}")" + completions="$(pyenv completions "${words[2,-1]}")" fi reply=("${(ps:\n:)completions}") diff --git a/libexec/pyenv-exec b/libexec/pyenv-exec index 30f4191e..57fa0865 100755 --- a/libexec/pyenv-exec +++ b/libexec/pyenv-exec @@ -21,6 +21,7 @@ if [ "$1" = "--complete" ]; then exec pyenv shims --short fi +export PYENV_VERSION="$(pyenv-version-name)" PYENV_COMMAND="$1" if [ -z "$PYENV_COMMAND" ]; then @@ -36,5 +37,7 @@ for script in $(pyenv-hooks exec); do done shift 1 -export PATH="${PYENV_BIN_PATH}:${PATH}" +if [ "$PYENV_VERSION" != "system" ]; then + export PATH="${PYENV_BIN_PATH}:${PATH}" +fi exec -a "$PYENV_COMMAND" "$PYENV_COMMAND_PATH" "$@" diff --git a/libexec/pyenv-init b/libexec/pyenv-init index f8012827..fd2e2c2f 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -85,11 +85,12 @@ if [ -z "$no_rehash" ]; then echo 'pyenv rehash 2>/dev/null' fi -commands=(`pyenv commands --sh`) +commands=(`pyenv-commands --sh`) IFS="|" cat < "$PROTOTYPE_SHIM_PATH" </dev/null 2>&1; then + for shim in *; do rm -f "$shim"; done + fi + break + done +} + # The basename of each argument passed to `make_shims` will be # registered for installation as a shim. In this way, plugins may call # `make_shims` with a glob to register many shims at once. @@ -57,58 +86,27 @@ make_shims() { done } -# Create an empty array for the list of registered shims. +# Create an empty array for the list of registered shims and an empty +# string to use as a search index. registered_shims=() +registered_shims_index="" # We will keep track of shims registered for installation with the -# global `reigstered_shims` array and with a global variable for each -# shim. The array will let us iterate over all registered shims. The -# global variables will let us quickly check whether a shim with the -# given name has been registered or not. +# global `reigstered_shims` array and with a global search index +# string. The array will let us iterate over all registered shims. The +# index string will let us quickly check whether a shim with the given +# name has been registered or not. register_shim() { local shim="$@" - local var="$(shim_variable_name "$shim")" - - if [ -z "${!var}" ]; then - registered_shims[${#registered_shims[*]}]="$shim" - eval "${var}=1" - fi -} - -# To compute the global variable name for a given shim we must first -# escape any non-alphanumeric characters. If the shim name is -# alphanumeric (including a hyphen or underscore) we can take a -# shorter path. Otherwise, we must iterate over each character and -# escape the non-alphanumeric ones using `printf`. -shim_variable_name() { - local shim="$1" - local result="_shim_" - - if [[ ! "$shim" =~ [^[:alnum:]_-] ]]; then - shim="${shim//_/_5f}" - shim="${shim//-/_2d}" - result="$result$shim" - else - local length="${#shim}" - local char i - - for ((i=0; i/dev/null - -IFS=: PYENV_VERSION="${versions[*]}" -echo "export PYENV_VERSION=\"${PYENV_VERSION}\"" +if pyenv-prefix "${versions[@]}" >/dev/null + IFS=: PYENV_VERSION="${versions[*]}" + echo "export PYENV_VERSION=\"${PYENV_VERSION}\"" +else + echo "return 1" + exit 1 +fi diff --git a/libexec/pyenv-version-file-read b/libexec/pyenv-version-file-read index c29577d8..cd752660 100755 --- a/libexec/pyenv-version-file-read +++ b/libexec/pyenv-version-file-read @@ -6,8 +6,8 @@ set -e VERSION_FILE="$1" if [ -e "$VERSION_FILE" ]; then - # Read and print the first non-whitespace word from the specified - # version file. + # Read the first non-whitespace word from the specified version file. + # Be careful not to load it whole in case there's something crazy in it. versions=() while read -a words; do word="${words[0]}" diff --git a/libexec/pyenv-version-name b/libexec/pyenv-version-name index 85d9c1d0..49a4aa34 100755 --- a/libexec/pyenv-version-name +++ b/libexec/pyenv-version-name @@ -17,10 +17,15 @@ if [ -z "$versions" ]; then exit fi +version_exists() { + local version="$1" + [ -d "${RBENV_ROOT}/versions/${version}" ] +} + for version in "${versions[@]}"; do PYENV_VERSION_PATH="${PYENV_ROOT}/versions/${version}" - - if [ "$version" != "system" ] && [ ! -d "$PYENV_VERSION_PATH" ]; then + + if [ "$version" != "system" ] && version_exists "$version"; then echo "pyenv: version \`$version' is not installed" >&2 exit 1 fi diff --git a/libexec/pyenv-versions b/libexec/pyenv-versions index 3dac25e3..648a7ed2 100755 --- a/libexec/pyenv-versions +++ b/libexec/pyenv-versions @@ -7,6 +7,20 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x +if [ "$1" = "--bare" ]; then + hit_prefix="" + miss_prefix="" + IFS=: current_versions=() + version_origin="" + include_system="" +else + hit_prefix="* " + miss_prefix=" " + IFS=: current_versions=($(pyenv-version-name || true)) + version_origin=" (set by $(pyenv-version-origin))" + include_system="1" +fi + array_exists() { local x car="$1" shift @@ -16,26 +30,21 @@ array_exists() { return 1 } -IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) +print_version() { + if array_exists "$1" "${current_versions[@]}"; then + echo "${hit_prefix}${1}${version_origin}" + else + echo "${miss_prefix}${1}" + fi +} -if [ "$1" = "--bare" ]; then - hit_prefix="" - miss_prefix="" - version_origin="" -else - hit_prefix="* " - miss_prefix=" " - version_origin=" (set by $(pyenv-version-origin))" +# Include "system" in the non-bare output, if it exists +if [ -n "$include_system" ] && PYENV_VERSION=system pyenv-which python >/dev/null 2>&1; then + print_version system fi for path in "${PYENV_ROOT}/versions/"*; do if [ -d "$path" ]; then - version="${path##*/}" - - if array_exists "$version" "${PYENV_VERSION_NAMES[@]}"; then - echo "${hit_prefix}${version}${version_origin}" - else - echo "${miss_prefix}${version}" - fi + print_version "${path##*/}" fi done diff --git a/libexec/pyenv-which b/libexec/pyenv-which index afb8e3e9..283d894a 100755 --- a/libexec/pyenv-which +++ b/libexec/pyenv-which @@ -77,5 +77,15 @@ if [ -x "$PYENV_COMMAND_PATH" ]; then echo "$PYENV_COMMAND_PATH" else echo "pyenv: $PYENV_COMMAND: command not found" >&2 + + versions="$(pyenv-whence "$PYENV_COMMAND" || true)" + if [ -n "$versions" ]; then + { echo + echo "The \`$1' command exists in these Ruby versions:" + echo "$versions" | sed 's/^/ /g' + echo + } >&2 + fi + exit 127 fi