mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-22 14:33:41 +00: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
|
||||
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() {
|
||||
$(type -p greadlink readlink | head -1) "$1"
|
||||
$READLINK "$1"
|
||||
}
|
||||
|
||||
abs_dirname() {
|
||||
|
|
|
@ -14,8 +14,9 @@ set -e
|
|||
|
||||
version="0.4.0-20131217"
|
||||
|
||||
cd "$PYENV_ROOT"
|
||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||
git_revision="${git_revision#v}"
|
||||
if cd "$PYENV_ROOT" 2>/dev/null; then
|
||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||
git_revision="${git_revision#v}"
|
||||
fi
|
||||
|
||||
echo "pyenv ${git_revision:-$version}"
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
# Runs an executable by first preparing PATH so that the selected Python
|
||||
# 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
|
||||
#
|
||||
# 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
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
@ -21,7 +21,7 @@ if [ "$1" = "--complete" ]; then
|
|||
exec pyenv shims --short
|
||||
fi
|
||||
|
||||
export PYENV_VERSION="$(pyenv-version-name)"
|
||||
PYENV_VERSION="$(pyenv-version-name)"
|
||||
PYENV_COMMAND="$1"
|
||||
|
||||
if [ -z "$PYENV_COMMAND" ]; then
|
||||
|
@ -29,10 +29,14 @@ if [ -z "$PYENV_COMMAND" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
export PYENV_VERSION
|
||||
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
|
||||
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"
|
||||
done
|
||||
|
||||
|
|
|
@ -19,13 +19,18 @@ if [ -z "$PYENV_COMMAND" ]; then
|
|||
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() {
|
||||
$(type -p greadlink readlink | head -1) $1
|
||||
$READLINK "$1"
|
||||
}
|
||||
|
||||
realpath() {
|
||||
local cwd="$(pwd)"
|
||||
local base="$(basename $1)"
|
||||
local path="$1"
|
||||
|
||||
while [ -n "$path" ]; do
|
||||
|
@ -34,13 +39,15 @@ realpath() {
|
|||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
echo "$(pwd)/$base"
|
||||
echo "$(pwd)/$name"
|
||||
cd "$cwd"
|
||||
}
|
||||
|
||||
IFS=: hook_paths=($PYENV_HOOK_PATH)
|
||||
|
||||
shopt -s nullglob
|
||||
for path in ${PYENV_HOOK_PATH//:/$'\n'}; do
|
||||
for script in $path/"$PYENV_COMMAND"/*.bash; do
|
||||
for path in "${hook_paths[@]}"; do
|
||||
for script in "$path/$PYENV_COMMAND"/*.bash; do
|
||||
echo $(realpath $script)
|
||||
done
|
||||
done
|
||||
|
|
|
@ -17,7 +17,11 @@ mkdir -p "$SHIM_PATH"
|
|||
set -o noclobber
|
||||
{ echo > "$PROTOTYPE_SHIM_PATH"
|
||||
} 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
|
||||
} >&2
|
||||
set +o noclobber
|
||||
|
@ -78,9 +82,9 @@ remove_outdated_shims() {
|
|||
# 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() {
|
||||
local shims="$@"
|
||||
local shims=("$@")
|
||||
|
||||
for file in $shims; do
|
||||
for file in "${shims[@]}"; do
|
||||
local shim="${file##*/}"
|
||||
register_shim "$shim"
|
||||
done
|
||||
|
@ -92,7 +96,7 @@ registered_shims=()
|
|||
registered_shims_index=""
|
||||
|
||||
# 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
|
||||
# index string will let us quickly check whether a shim with the given
|
||||
# name has been registered or not.
|
||||
|
@ -140,7 +144,11 @@ make_shims ../versions/*/bin/*
|
|||
cd "$OLDPWD"
|
||||
|
||||
# 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"
|
||||
done
|
||||
|
||||
|
|
|
@ -51,14 +51,14 @@ fi
|
|||
# Make sure the specified version is installed.
|
||||
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
||||
OLDIFS="$IFS"
|
||||
IFS=: PYENV_VERSION="${versions[*]}"
|
||||
IFS=: version="${versions[*]}"
|
||||
IFS="$OLDIFS"
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "setenv PYENV_VERSION \"${PYENV_VERSION}\""
|
||||
echo "setenv PYENV_VERSION \"${version}\""
|
||||
;;
|
||||
* )
|
||||
echo "export PYENV_VERSION=\"${PYENV_VERSION}\""
|
||||
echo "export PYENV_VERSION=\"${version}\""
|
||||
;;
|
||||
esac
|
||||
else
|
||||
|
|
|
@ -11,6 +11,8 @@ if [ "$1" = "--complete" ]; then
|
|||
exit
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
for command in "${PYENV_ROOT}/shims/"*; do
|
||||
if [ "$1" = "--short" ]; then
|
||||
echo "${command##*/}"
|
||||
|
|
|
@ -8,14 +8,8 @@ VERSION_FILE="$1"
|
|||
if [ -e "$VERSION_FILE" ]; then
|
||||
# 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]}"
|
||||
if [ -n "$word" ]; then
|
||||
length="${#versions[@]}"
|
||||
versions=("${versions[@]}" "$word")
|
||||
fi
|
||||
done < <( cat "$VERSION_FILE" && echo )
|
||||
words=( $(cut -b 1-1024 "$VERSION_FILE") )
|
||||
versions=("${words[@]}")
|
||||
|
||||
if [ -n "$versions" ]; then
|
||||
OLDIFS="$IFS"
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
if [ -n "$PYENV_VERSION" ]; then
|
||||
OLDIFS="$IFS"
|
||||
IFS=: versions=($(echo "${PYENV_VERSION}"))
|
||||
IFS="$IFS"
|
||||
else
|
||||
if [ -z "$PYENV_VERSION" ]; then
|
||||
PYENV_VERSION_FILE="$(pyenv-version-file)"
|
||||
OLDIFS="$IFS"
|
||||
IFS=: versions=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true))
|
||||
IFS=: PYENV_VERSION="${versions[*]}"
|
||||
IFS="$OLDIFS"
|
||||
export PYENV_VERSION
|
||||
else
|
||||
OLDIFS="$IFS"
|
||||
IFS=: versions=($(echo "${PYENV_VERSION}"))
|
||||
IFS="$IFS"
|
||||
fi
|
||||
|
||||
if [ -z "$versions" ]; then
|
||||
if [ -z "$versions" ] || [ "$versions" = "system" ]; then
|
||||
echo "system"
|
||||
exit
|
||||
fi
|
||||
|
|
|
@ -34,9 +34,9 @@ array_exists() {
|
|||
|
||||
print_version() {
|
||||
if array_exists "$1" "${current_versions[@]}"; then
|
||||
echo "${hit_prefix}${1}${version_origin}"
|
||||
echo "${hit_prefix}$1${version_origin}"
|
||||
else
|
||||
echo "${miss_prefix}${1}"
|
||||
echo "${miss_prefix}$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -36,9 +36,7 @@ remove_from_path() {
|
|||
fi
|
||||
|
||||
local paths
|
||||
OLDIFS="$IFS"
|
||||
IFS=: paths=($PATH)
|
||||
IFS="$OLDIFS"
|
||||
|
||||
for path in "${paths[@]}"; do
|
||||
path="$(expand_path "$path" || true)"
|
||||
|
@ -73,7 +71,10 @@ for version in "${versions[@]}"; do
|
|||
fi
|
||||
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"
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in a new issue