1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-15 14:53:53 -05:00

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

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

View File

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

View File

@@ -13,10 +13,14 @@ set -e
[ -n "$PYENV_DEBUG" ] && set -x
version="20151105"
git_revision=""
if cd "$PYENV_ROOT" 2>/dev/null; then
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
git_revision="${git_revision#v}"
fi
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_revision#v}"
[ -z "$git_revision" ] || break
fi
done
echo "pyenv ${git_revision:-$version}"

View File

@@ -10,7 +10,16 @@ if [ -z "$COMMAND" ]; then
exit 1
fi
# Provide pyenv completions
if [ "$COMMAND" = "--complete" ]; then
exec pyenv-commands
fi
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
shift
exec "$COMMAND_PATH" --complete "$@"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -28,7 +28,7 @@ OLDIFS="$IFS"
elif version_exists "${version#python-}"; then
versions=("${versions[@]}" "${version#python-}")
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
fi
done

View File

@@ -1,13 +1,69 @@
#!/usr/bin/env bash
# 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/*'.
set -e
[ -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=""
miss_prefix=""
current_versions=()
@@ -50,8 +106,12 @@ if [ -n "$include_system" ] && PYENV_VERSION=system pyenv-which python >/dev/nul
fi
shopt -s nullglob
for path in "${PYENV_ROOT}/versions/"*; do
for path in "$versions_dir"/*; do
if [ -d "$path" ]; then
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
target="$(realpath "$path")"
[ "${target%/*}" != "$versions_dir" ] || continue
fi
print_version "${path##*/}"
# virtual environments created by anaconda/miniconda
for env_path in "${path}/envs/"*; do

View File

@@ -58,6 +58,9 @@ done
if [ -x "$PYENV_COMMAND_PATH" ]; then
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
any_not_installed=0
for version in "${versions[@]}"; do