mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
import trivial changes from rbenv 0.4.0
This commit is contained in:
parent
684f7b7f21
commit
fca31c4307
12 changed files with 136 additions and 85 deletions
|
@ -13,4 +13,11 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
export PYENV_DIR="${1%/*}"
|
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 "$@"
|
exec python "$@"
|
||||||
|
|
|
@ -5,8 +5,10 @@ _pyenv() {
|
||||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||||
COMPREPLY=( $(compgen -W "$(pyenv commands)" -- "$word") )
|
COMPREPLY=( $(compgen -W "$(pyenv commands)" -- "$word") )
|
||||||
else
|
else
|
||||||
local command="${COMP_WORDS[1]}"
|
local words=("${COMP_WORDS[@]}")
|
||||||
local completions="$(pyenv completions "$command")"
|
unset words[0]
|
||||||
|
unset words[$COMP_CWORD]
|
||||||
|
local completions=$(pyenv completions "${words[@]}")
|
||||||
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,13 @@ fi
|
||||||
compctl -K _pyenv pyenv
|
compctl -K _pyenv pyenv
|
||||||
|
|
||||||
_pyenv() {
|
_pyenv() {
|
||||||
local word words completions
|
local words completions
|
||||||
read -cA words
|
read -cA words
|
||||||
word="${words[2]}"
|
|
||||||
|
|
||||||
if [ "${#words}" -eq 2 ]; then
|
if [ "${#words}" -eq 2 ]; then
|
||||||
completions="$(pyenv commands)"
|
completions="$(pyenv commands)"
|
||||||
else
|
else
|
||||||
completions="$(pyenv completions "${word}")"
|
completions="$(pyenv completions "${words[2,-1]}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reply=("${(ps:\n:)completions}")
|
reply=("${(ps:\n:)completions}")
|
||||||
|
|
|
@ -21,6 +21,7 @@ if [ "$1" = "--complete" ]; then
|
||||||
exec pyenv shims --short
|
exec pyenv shims --short
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export PYENV_VERSION="$(pyenv-version-name)"
|
||||||
PYENV_COMMAND="$1"
|
PYENV_COMMAND="$1"
|
||||||
|
|
||||||
if [ -z "$PYENV_COMMAND" ]; then
|
if [ -z "$PYENV_COMMAND" ]; then
|
||||||
|
@ -36,5 +37,7 @@ for script in $(pyenv-hooks exec); do
|
||||||
done
|
done
|
||||||
|
|
||||||
shift 1
|
shift 1
|
||||||
|
if [ "$PYENV_VERSION" != "system" ]; then
|
||||||
export PATH="${PYENV_BIN_PATH}:${PATH}"
|
export PATH="${PYENV_BIN_PATH}:${PATH}"
|
||||||
|
fi
|
||||||
exec -a "$PYENV_COMMAND" "$PYENV_COMMAND_PATH" "$@"
|
exec -a "$PYENV_COMMAND" "$PYENV_COMMAND_PATH" "$@"
|
||||||
|
|
|
@ -85,11 +85,12 @@ if [ -z "$no_rehash" ]; then
|
||||||
echo 'pyenv rehash 2>/dev/null'
|
echo 'pyenv rehash 2>/dev/null'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
commands=(`pyenv commands --sh`)
|
commands=(`pyenv-commands --sh`)
|
||||||
IFS="|"
|
IFS="|"
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
pyenv() {
|
pyenv() {
|
||||||
local command="\$1"
|
typeset command
|
||||||
|
command="\$1"
|
||||||
if [ "\$#" -gt 0 ]; then
|
if [ "\$#" -gt 0 ]; then
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -32,19 +32,48 @@ remove_prototype_shim() {
|
||||||
|
|
||||||
# The prototype shim file is a script that re-execs itself, passing
|
# The prototype shim file is a script that re-execs itself, passing
|
||||||
# its filename and any arguments to `pyenv exec`. This file is
|
# its filename and any arguments to `pyenv exec`. This file is
|
||||||
# hard-linked for every binary and then removed. The linking technique
|
# hard-linked for every executable and then removed. The linking
|
||||||
# is fast, uses less disk space than unique files, and also serves as
|
# technique is fast, uses less disk space than unique files, and also
|
||||||
# a locking mechanism.
|
# serves as a locking mechanism.
|
||||||
create_prototype_shim() {
|
create_prototype_shim() {
|
||||||
cat > "$PROTOTYPE_SHIM_PATH" <<SH
|
cat > "$PROTOTYPE_SHIM_PATH" <<SH
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
[ -n "\$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
program="\${0##*/}"
|
||||||
|
if [ "\$program" = "python" ]; then
|
||||||
|
for arg; do
|
||||||
|
case "\$arg" in
|
||||||
|
-c* | -- ) break ;;
|
||||||
|
*/* )
|
||||||
|
if [ -f "\$arg" ]; then
|
||||||
|
export PYENV_DIR="\${arg%/*}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
export PYENV_ROOT="$PYENV_ROOT"
|
export PYENV_ROOT="$PYENV_ROOT"
|
||||||
exec pyenv exec "\${0##*/}" "\$@"
|
exec "$(command -v pyenv)" exec "\$program" "\$@"
|
||||||
SH
|
SH
|
||||||
chmod +x "$PROTOTYPE_SHIM_PATH"
|
chmod +x "$PROTOTYPE_SHIM_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If the contents of the prototype shim file differ from the contents
|
||||||
|
# of the first shim in the shims directory, assume rbenv has been
|
||||||
|
# upgraded and the existing shims need to be removed.
|
||||||
|
remove_outdated_shims() {
|
||||||
|
for shim in *; do
|
||||||
|
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/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
|
# The basename of each argument passed to `make_shims` will be
|
||||||
# registered for installation as a shim. In this way, plugins may call
|
# registered for installation as a shim. In this way, plugins may call
|
||||||
# `make_shims` with a glob to register many shims at once.
|
# `make_shims` with a glob to register many shims at once.
|
||||||
|
@ -57,58 +86,27 @@ make_shims() {
|
||||||
done
|
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=()
|
||||||
|
registered_shims_index=""
|
||||||
|
|
||||||
# We will keep track of shims registered for installation with the
|
# We will keep track of shims registered for installation with the
|
||||||
# global `reigstered_shims` array and with a global variable for each
|
# global `reigstered_shims` array and with a global search index
|
||||||
# shim. The array will let us iterate over all registered shims. The
|
# string. The array will let us iterate over all registered shims. The
|
||||||
# global variables will let us quickly check whether a shim with the
|
# index string will let us quickly check whether a shim with the given
|
||||||
# given name has been registered or not.
|
# name has been registered or not.
|
||||||
register_shim() {
|
register_shim() {
|
||||||
local shim="$@"
|
local shim="$@"
|
||||||
local var="$(shim_variable_name "$shim")"
|
registered_shims["${#registered_shims[@]}"]="$shim"
|
||||||
|
registered_shims_index="$registered_shims_index/$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<length; i++)); do
|
|
||||||
char="${shim:$i:1}"
|
|
||||||
if [[ "$char" =~ [[:alnum:]] ]]; then
|
|
||||||
result="$result$char"
|
|
||||||
else
|
|
||||||
result="$result$(printf "_%02x" \'"$char")"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$result"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# To install all the registered shims, we iterate over the
|
# To install all the registered shims, we iterate over the
|
||||||
# `registered_shims` array and create a link if one does not already
|
# `registered_shims` array and create a link if one does not already
|
||||||
# exist.
|
# exist.
|
||||||
install_registered_shims() {
|
install_registered_shims() {
|
||||||
|
local shim
|
||||||
for shim in "${registered_shims[@]}"; do
|
for shim in "${registered_shims[@]}"; do
|
||||||
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
|
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
|
||||||
done
|
done
|
||||||
|
@ -119,10 +117,9 @@ install_registered_shims() {
|
||||||
# in the directory but has not been registered as a shim should be
|
# in the directory but has not been registered as a shim should be
|
||||||
# removed.
|
# removed.
|
||||||
remove_stale_shims() {
|
remove_stale_shims() {
|
||||||
local var
|
local shim
|
||||||
for shim in *; do
|
for shim in *; do
|
||||||
var="$(shim_variable_name "$shim")"
|
if [[ "$registered_shims_index" != *"/$shim/"* ]]; then
|
||||||
if [ -z "${!var}" ]; then
|
|
||||||
rm -f "$shim"
|
rm -f "$shim"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -131,10 +128,12 @@ remove_stale_shims() {
|
||||||
|
|
||||||
# Change to the shims directory.
|
# Change to the shims directory.
|
||||||
cd "$SHIM_PATH"
|
cd "$SHIM_PATH"
|
||||||
|
|
||||||
# Create the prototype shim, then register shims for all known binaries.
|
|
||||||
create_prototype_shim
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
|
# Create the prototype shim, then register shims for all known
|
||||||
|
# executables.
|
||||||
|
create_prototype_shim
|
||||||
|
remove_outdated_shims
|
||||||
make_shims ../versions/*/bin/*
|
make_shims ../versions/*/bin/*
|
||||||
|
|
||||||
# Restore the previous working directory.
|
# Restore the previous working directory.
|
||||||
|
|
13
libexec/pyenv-sh-rehash
Executable file
13
libexec/pyenv-sh-rehash
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
# Provide pyenv completions
|
||||||
|
if [ "$1" = "--complete" ]; then
|
||||||
|
exec pyenv-rehash --complete
|
||||||
|
fi
|
||||||
|
|
||||||
|
# When pyenv shell integration is enabled, delegate to pyenv-rehash,
|
||||||
|
# then tell the shell to empty its command lookup cache.
|
||||||
|
pyenv-rehash
|
||||||
|
echo "hash -r"
|
|
@ -37,11 +37,14 @@ fi
|
||||||
|
|
||||||
if [ "$versions" = "--unset" ]; then
|
if [ "$versions" = "--unset" ]; then
|
||||||
echo "unset PYENV_VERSION"
|
echo "unset PYENV_VERSION"
|
||||||
exit 1
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make sure the specified version is installed.
|
# Make sure the specified version is installed.
|
||||||
pyenv-prefix "${versions[@]}" >/dev/null
|
if pyenv-prefix "${versions[@]}" >/dev/null
|
||||||
|
|
||||||
IFS=: PYENV_VERSION="${versions[*]}"
|
IFS=: PYENV_VERSION="${versions[*]}"
|
||||||
echo "export PYENV_VERSION=\"${PYENV_VERSION}\""
|
echo "export PYENV_VERSION=\"${PYENV_VERSION}\""
|
||||||
|
else
|
||||||
|
echo "return 1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
|
@ -6,8 +6,8 @@ set -e
|
||||||
VERSION_FILE="$1"
|
VERSION_FILE="$1"
|
||||||
|
|
||||||
if [ -e "$VERSION_FILE" ]; then
|
if [ -e "$VERSION_FILE" ]; then
|
||||||
# Read and print the first non-whitespace word from the specified
|
# Read the first non-whitespace word from the specified version file.
|
||||||
# version file.
|
# Be careful not to load it whole in case there's something crazy in it.
|
||||||
versions=()
|
versions=()
|
||||||
while read -a words; do
|
while read -a words; do
|
||||||
word="${words[0]}"
|
word="${words[0]}"
|
||||||
|
|
|
@ -17,10 +17,15 @@ if [ -z "$versions" ]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
version_exists() {
|
||||||
|
local version="$1"
|
||||||
|
[ -d "${RBENV_ROOT}/versions/${version}" ]
|
||||||
|
}
|
||||||
|
|
||||||
for version in "${versions[@]}"; do
|
for version in "${versions[@]}"; do
|
||||||
PYENV_VERSION_PATH="${PYENV_ROOT}/versions/${version}"
|
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
|
echo "pyenv: version \`$version' is not installed" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -7,6 +7,20 @@
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -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() {
|
array_exists() {
|
||||||
local x car="$1"
|
local x car="$1"
|
||||||
shift
|
shift
|
||||||
|
@ -16,26 +30,21 @@ array_exists() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name))
|
print_version() {
|
||||||
|
if array_exists "$1" "${current_versions[@]}"; then
|
||||||
if [ "$1" = "--bare" ]; then
|
echo "${hit_prefix}${1}${version_origin}"
|
||||||
hit_prefix=""
|
|
||||||
miss_prefix=""
|
|
||||||
version_origin=""
|
|
||||||
else
|
else
|
||||||
hit_prefix="* "
|
echo "${miss_prefix}${1}"
|
||||||
miss_prefix=" "
|
fi
|
||||||
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
|
fi
|
||||||
|
|
||||||
for path in "${PYENV_ROOT}/versions/"*; do
|
for path in "${PYENV_ROOT}/versions/"*; do
|
||||||
if [ -d "$path" ]; then
|
if [ -d "$path" ]; then
|
||||||
version="${path##*/}"
|
print_version "${path##*/}"
|
||||||
|
|
||||||
if array_exists "$version" "${PYENV_VERSION_NAMES[@]}"; then
|
|
||||||
echo "${hit_prefix}${version}${version_origin}"
|
|
||||||
else
|
|
||||||
echo "${miss_prefix}${version}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
@ -77,5 +77,15 @@ if [ -x "$PYENV_COMMAND_PATH" ]; then
|
||||||
echo "$PYENV_COMMAND_PATH"
|
echo "$PYENV_COMMAND_PATH"
|
||||||
else
|
else
|
||||||
echo "pyenv: $PYENV_COMMAND: command not found" >&2
|
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
|
exit 127
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue