mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-14 20:39:55 -05:00
Import recent changes from rbenv 0.4.0
This commit is contained in:
parent
8fa6b4a184
commit
8ddf8760d5
11 changed files with 74 additions and 41 deletions
|
@ -1,9 +1,25 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
export -n CDPATH
|
||||||
|
|
||||||
|
if [ "$1" = "--debug" ]; then
|
||||||
|
export PYENV_DEBUG=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$PYENV_DEBUG" ]; then
|
||||||
|
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
|
||||||
|
set -x
|
||||||
|
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() {
|
resolve_link() {
|
||||||
$(type -p greadlink readlink | head -1) "$1"
|
$READLINK "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
|
|
|
@ -14,8 +14,9 @@ set -e
|
||||||
|
|
||||||
version="0.4.0-20131217"
|
version="0.4.0-20131217"
|
||||||
|
|
||||||
cd "$PYENV_ROOT"
|
if cd "$PYENV_ROOT" 2>/dev/null; then
|
||||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||||
git_revision="${git_revision#v}"
|
git_revision="${git_revision#v}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "pyenv ${git_revision:-$version}"
|
echo "pyenv ${git_revision:-$version}"
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
# Runs an executable by first preparing PATH so that the selected Python
|
# Runs an executable by first preparing PATH so that the selected Python
|
||||||
# version's `bin' directory is at the front.
|
# version's `bin' directory is at the front.
|
||||||
#
|
#
|
||||||
# For example, if the currently selected Python version is 2.7.7:
|
# For example, if the currently selected Python version is 2.7.6:
|
||||||
# pyenv exec pip install -rrequirements.txt
|
# pyenv exec pip install -rrequirements.txt
|
||||||
#
|
#
|
||||||
# is equivalent to:
|
# is equivalent to:
|
||||||
# PATH="$PYENV_ROOT/versions/2.7.7/bin:$PATH" pip install -rrequirements.txt
|
# PATH="$PYENV_ROOT/versions/2.7.6/bin:$PATH" pip install -rrequirements.txt
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
@ -21,7 +21,7 @@ if [ "$1" = "--complete" ]; then
|
||||||
exec pyenv shims --short
|
exec pyenv shims --short
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export PYENV_VERSION="$(pyenv-version-name)"
|
PYENV_VERSION="$(pyenv-version-name)"
|
||||||
PYENV_COMMAND="$1"
|
PYENV_COMMAND="$1"
|
||||||
|
|
||||||
if [ -z "$PYENV_COMMAND" ]; then
|
if [ -z "$PYENV_COMMAND" ]; then
|
||||||
|
@ -29,10 +29,14 @@ if [ -z "$PYENV_COMMAND" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export PYENV_VERSION
|
||||||
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
|
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
|
||||||
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
|
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
|
||||||
|
|
||||||
for script in $(pyenv-hooks exec); do
|
OLDIFS="$IFS"
|
||||||
|
IFS=$'\n' scripts=(`rbenv-hooks exec`)
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
for script in "${scripts[@]}"; do
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,18 @@ if [ -z "$PYENV_COMMAND" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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() {
|
resolve_link() {
|
||||||
$(type -p greadlink readlink | head -1) $1
|
$READLINK "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
realpath() {
|
realpath() {
|
||||||
local cwd="$(pwd)"
|
local cwd="$(pwd)"
|
||||||
local base="$(basename $1)"
|
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
while [ -n "$path" ]; do
|
||||||
|
@ -34,13 +39,15 @@ realpath() {
|
||||||
path="$(resolve_link "$name" || true)"
|
path="$(resolve_link "$name" || true)"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "$(pwd)/$base"
|
echo "$(pwd)/$name"
|
||||||
cd "$cwd"
|
cd "$cwd"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IFS=: hook_paths=($PYENV_HOOK_PATH)
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
for path in ${PYENV_HOOK_PATH//:/$'\n'}; do
|
for path in "${hook_paths[@]}"; do
|
||||||
for script in $path/"$PYENV_COMMAND"/*.bash; do
|
for script in "$path/$PYENV_COMMAND"/*.bash; do
|
||||||
echo $(realpath $script)
|
echo $(realpath $script)
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
|
@ -17,7 +17,11 @@ mkdir -p "$SHIM_PATH"
|
||||||
set -o noclobber
|
set -o noclobber
|
||||||
{ echo > "$PROTOTYPE_SHIM_PATH"
|
{ echo > "$PROTOTYPE_SHIM_PATH"
|
||||||
} 2>/dev/null ||
|
} 2>/dev/null ||
|
||||||
{ echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
|
{ if [ -w "$SHIM_PATH" ]; then
|
||||||
|
echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
|
||||||
|
else
|
||||||
|
echo "pyenv: cannot rehash: $SHIM_PATH isn't writable"
|
||||||
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
} >&2
|
} >&2
|
||||||
set +o noclobber
|
set +o noclobber
|
||||||
|
@ -78,9 +82,9 @@ remove_outdated_shims() {
|
||||||
# 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.
|
||||||
make_shims() {
|
make_shims() {
|
||||||
local shims="$@"
|
local shims=("$@")
|
||||||
|
|
||||||
for file in $shims; do
|
for file in "${shims[@]}"; do
|
||||||
local shim="${file##*/}"
|
local shim="${file##*/}"
|
||||||
register_shim "$shim"
|
register_shim "$shim"
|
||||||
done
|
done
|
||||||
|
@ -92,7 +96,7 @@ registered_shims=()
|
||||||
registered_shims_index=""
|
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 search index
|
# global `registered_shims` array and with a global search index
|
||||||
# string. The array will let us iterate over all registered shims. The
|
# 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
|
# index string will let us quickly check whether a shim with the given
|
||||||
# name has been registered or not.
|
# name has been registered or not.
|
||||||
|
@ -140,7 +144,11 @@ make_shims ../versions/*/bin/*
|
||||||
cd "$OLDPWD"
|
cd "$OLDPWD"
|
||||||
|
|
||||||
# Allow plugins to register shims.
|
# Allow plugins to register shims.
|
||||||
for script in $(pyenv-hooks rehash); do
|
OLDIFS="$IFS"
|
||||||
|
IFS=$'\n' scripts=(`pyenv-hooks rehash`)
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
|
||||||
|
for script in "${scripts[@]}"; do
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -51,14 +51,14 @@ fi
|
||||||
# Make sure the specified version is installed.
|
# Make sure the specified version is installed.
|
||||||
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=: PYENV_VERSION="${versions[*]}"
|
IFS=: version="${versions[*]}"
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish )
|
fish )
|
||||||
echo "setenv PYENV_VERSION \"${PYENV_VERSION}\""
|
echo "setenv PYENV_VERSION \"${version}\""
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
echo "export PYENV_VERSION=\"${PYENV_VERSION}\""
|
echo "export PYENV_VERSION=\"${version}\""
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
|
|
|
@ -11,6 +11,8 @@ if [ "$1" = "--complete" ]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
for command in "${PYENV_ROOT}/shims/"*; do
|
for command in "${PYENV_ROOT}/shims/"*; do
|
||||||
if [ "$1" = "--short" ]; then
|
if [ "$1" = "--short" ]; then
|
||||||
echo "${command##*/}"
|
echo "${command##*/}"
|
||||||
|
|
|
@ -8,14 +8,8 @@ VERSION_FILE="$1"
|
||||||
if [ -e "$VERSION_FILE" ]; then
|
if [ -e "$VERSION_FILE" ]; then
|
||||||
# Read 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.
|
# Be careful not to load it whole in case there's something crazy in it.
|
||||||
versions=()
|
words=( $(cut -b 1-1024 "$VERSION_FILE") )
|
||||||
while read -a words; do
|
versions=("${words[@]}")
|
||||||
word="${words[0]}"
|
|
||||||
if [ -n "$word" ]; then
|
|
||||||
length="${#versions[@]}"
|
|
||||||
versions=("${versions[@]}" "$word")
|
|
||||||
fi
|
|
||||||
done < <( cat "$VERSION_FILE" && echo )
|
|
||||||
|
|
||||||
if [ -n "$versions" ]; then
|
if [ -n "$versions" ]; then
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
if [ -n "$PYENV_VERSION" ]; then
|
if [ -z "$PYENV_VERSION" ]; then
|
||||||
OLDIFS="$IFS"
|
|
||||||
IFS=: versions=($(echo "${PYENV_VERSION}"))
|
|
||||||
IFS="$IFS"
|
|
||||||
else
|
|
||||||
PYENV_VERSION_FILE="$(pyenv-version-file)"
|
PYENV_VERSION_FILE="$(pyenv-version-file)"
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=: versions=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true))
|
IFS=: versions=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true))
|
||||||
IFS=: PYENV_VERSION="${versions[*]}"
|
IFS=: PYENV_VERSION="${versions[*]}"
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
export PYENV_VERSION
|
export PYENV_VERSION
|
||||||
|
else
|
||||||
|
OLDIFS="$IFS"
|
||||||
|
IFS=: versions=($(echo "${PYENV_VERSION}"))
|
||||||
|
IFS="$IFS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$versions" ]; then
|
if [ -z "$versions" ] || [ "$versions" = "system" ]; then
|
||||||
echo "system"
|
echo "system"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -34,9 +34,9 @@ array_exists() {
|
||||||
|
|
||||||
print_version() {
|
print_version() {
|
||||||
if array_exists "$1" "${current_versions[@]}"; then
|
if array_exists "$1" "${current_versions[@]}"; then
|
||||||
echo "${hit_prefix}${1}${version_origin}"
|
echo "${hit_prefix}$1${version_origin}"
|
||||||
else
|
else
|
||||||
echo "${miss_prefix}${1}"
|
echo "${miss_prefix}$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,7 @@ remove_from_path() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local paths
|
local paths
|
||||||
OLDIFS="$IFS"
|
|
||||||
IFS=: paths=($PATH)
|
IFS=: paths=($PATH)
|
||||||
IFS="$OLDIFS"
|
|
||||||
|
|
||||||
for path in "${paths[@]}"; do
|
for path in "${paths[@]}"; do
|
||||||
path="$(expand_path "$path" || true)"
|
path="$(expand_path "$path" || true)"
|
||||||
|
@ -73,7 +71,10 @@ for version in "${versions[@]}"; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for script in $(pyenv-hooks which); do
|
OLDIFS="$IFS"
|
||||||
|
IFS=$'\n' scripts=(`pyenv-hooks which`)
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
for script in "${scripts[@]}"; do
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue