mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Allow multiple versions for pyenv-install
This commit is contained in:
parent
ff93c58bab
commit
31f372034d
2 changed files with 202 additions and 146 deletions
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# Summary: Install a Python version using python-build
|
||||
#
|
||||
# Usage: pyenv install [-f] [-kvp] <version>
|
||||
# Usage: pyenv install [-f] [-kvp] <version>...
|
||||
# pyenv install [-f] [-kvp] <definition-file>
|
||||
# pyenv install -l|--list
|
||||
# pyenv install --version
|
||||
|
@ -113,17 +113,15 @@ for option in "${OPTIONS[@]}"; do
|
|||
esac
|
||||
done
|
||||
|
||||
[ "${#ARGUMENTS[@]}" -le 1 ] || usage 1 >&2
|
||||
|
||||
unset VERSION_NAME
|
||||
|
||||
# The first argument contains the definition to install. If the
|
||||
# argument is missing, try to install whatever local app-specific
|
||||
# version is specified by pyenv. Show usage instructions if a local
|
||||
# version is not specified.
|
||||
DEFINITION="${ARGUMENTS[0]}"
|
||||
[ -n "$DEFINITION" ] || DEFINITION="$(pyenv-local 2>/dev/null || true)"
|
||||
[ -n "$DEFINITION" ] || usage 1 >&2
|
||||
DEFINITIONS=("${ARGUMENTS[@]}")
|
||||
[ -n "${DEFINITIONS[*]}" ] || DEFINITIONS=($(pyenv-local 2>/dev/null || true))
|
||||
[ -n "${DEFINITIONS[*]}" ] || usage 1 >&2
|
||||
|
||||
# Define `before_install` and `after_install` functions that allow
|
||||
# plugin hooks to register a string of code for execution before or
|
||||
|
@ -140,19 +138,27 @@ after_install() {
|
|||
after_hooks["${#after_hooks[@]}"]="$hook"
|
||||
}
|
||||
|
||||
# Plan cleanup on unsuccessful installation.
|
||||
cleanup() {
|
||||
[ -z "${PREFIX_EXISTS}" ] && rm -rf "$PREFIX"
|
||||
}
|
||||
|
||||
trap cleanup SIGINT
|
||||
|
||||
|
||||
OLDIFS="$IFS"
|
||||
IFS=$'\n' scripts=(`pyenv-hooks install`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do source "$script"; done
|
||||
|
||||
for DEFINITION in "${DEFINITIONS[@]}";do
|
||||
# Try to resolve a prefix if user indeed gave a prefix.
|
||||
# We install the version under the resolved name
|
||||
# and hooks also see the resolved name
|
||||
DEFINITION="$(pyenv-latest -q -k "$DEFINITION" || echo "$DEFINITION")"
|
||||
|
||||
# Set VERSION_NAME from $DEFINITION, if it is not already set. Then
|
||||
# compute the installation prefix.
|
||||
[ -n "$VERSION_NAME" ] || VERSION_NAME="${DEFINITION##*/}"
|
||||
# Set VERSION_NAME from $DEFINITION. Then compute the installation prefix.
|
||||
VERSION_NAME="${DEFINITION##*/}"
|
||||
[ -n "$DEBUG" ] && VERSION_NAME="${VERSION_NAME}-debug"
|
||||
PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
|
||||
|
||||
|
@ -173,7 +179,7 @@ if [ -d "${PREFIX}/bin" ]; then
|
|||
# Since we know the python version is already installed, and are opting to
|
||||
# not force installation of existing versions, we just `exit 0` here to
|
||||
# leave things happy
|
||||
exit 0
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -240,13 +246,6 @@ fi
|
|||
# Execute `before_install` hooks.
|
||||
for hook in "${before_hooks[@]}"; do eval "$hook"; done
|
||||
|
||||
# Plan cleanup on unsuccessful installation.
|
||||
cleanup() {
|
||||
[ -z "${PREFIX_EXISTS}" ] && rm -rf "$PREFIX"
|
||||
}
|
||||
|
||||
trap cleanup SIGINT
|
||||
|
||||
# Invoke `python-build` and record the exit status in $STATUS.
|
||||
STATUS=0
|
||||
python-build $KEEP $VERBOSE $HAS_PATCH $DEBUG "$DEFINITION" "$PREFIX" || STATUS="$?"
|
||||
|
@ -283,7 +282,10 @@ for hook in "${after_hooks[@]}"; do eval "$hook"; done
|
|||
if [ "$STATUS" == "0" ]; then
|
||||
pyenv-rehash
|
||||
else
|
||||
break
|
||||
cleanup
|
||||
fi
|
||||
|
||||
exit "$STATUS"
|
||||
done
|
||||
|
||||
exit "${STATUS:-0}"
|
||||
|
|
|
@ -24,6 +24,26 @@ stub_python_build() {
|
|||
unstub pyenv-rehash
|
||||
}
|
||||
|
||||
@test "install proper multi versions" {
|
||||
#stub python-build "--lib : $BATS_TEST_DIRNAME/../bin/python-build --lib" 'echo python-build "$@"' 'echo python-build "$@"'
|
||||
#stub pyenv-latest ": false" ": false"
|
||||
stub_python_build 'echo python-build "$@"' 'echo python-build "$@"'
|
||||
stub pyenv-latest ": false"
|
||||
stub pyenv-rehash 'true'
|
||||
|
||||
run pyenv-install 3.4.1 3.4.2
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
python-build 3.4.1 ${TMP}/pyenv/versions/3.4.1
|
||||
python-build 3.4.2 ${TMP}/pyenv/versions/3.4.2
|
||||
OUT
|
||||
|
||||
unstub python-build
|
||||
unstub pyenv-latest
|
||||
unstub pyenv-hooks
|
||||
unstub pyenv-rehash
|
||||
}
|
||||
|
||||
@test "install resolves a prefix" {
|
||||
stub_python_build 'echo python-build "$@"'
|
||||
stub pyenv-latest '-q -k 3.4 : echo 3.4.2'
|
||||
|
@ -37,6 +57,24 @@ stub_python_build() {
|
|||
unstub pyenv-rehash
|
||||
}
|
||||
|
||||
@test "install resolves a prefix with multi versions" {
|
||||
stub_python_build 'echo python-build "$@"' 'echo python-build "$@"'
|
||||
stub pyenv-latest '-q -k 3.4 : echo 3.4.2' '-q -k 3.5 : echo 3.5.2'
|
||||
stub pyenv-rehash 'true'
|
||||
pyenv-latest || true # pass through the stub entry added by stub_python_build
|
||||
|
||||
run pyenv-install 3.4 3.5
|
||||
assert_success <<OUT
|
||||
python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2
|
||||
python-build 3.5.2 ${PYENV_ROOT}/versions/3.5.2
|
||||
OUT
|
||||
|
||||
|
||||
unstub python-build
|
||||
unstub pyenv-hooks
|
||||
unstub pyenv-rehash
|
||||
}
|
||||
|
||||
@test "install pyenv local version by default" {
|
||||
stub_python_build 'echo python-build "$1"'
|
||||
stub pyenv-local 'echo 3.4.2'
|
||||
|
@ -48,6 +86,21 @@ stub_python_build() {
|
|||
unstub pyenv-local
|
||||
}
|
||||
|
||||
@test "install pyenv local multi versions by default" {
|
||||
stub_python_build 'echo python-build "$1"' 'echo python-build "$1"'
|
||||
stub pyenv-local 'printf "%s\n%s\n" 3.4.2 3.4.1'
|
||||
stub pyenv-latest ": false"
|
||||
|
||||
run pyenv-install
|
||||
assert_success <<OUT
|
||||
python-build 3.4.2"
|
||||
python-build 3.4.1"
|
||||
OUT
|
||||
|
||||
unstub python-build
|
||||
unstub pyenv-local
|
||||
}
|
||||
|
||||
@test "list available versions" {
|
||||
stub_python_build \
|
||||
"--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
|
||||
|
@ -169,22 +222,23 @@ ${PYENV_ROOT}/plugins/foo/share/python-build
|
|||
OUT
|
||||
}
|
||||
|
||||
@test "not enough arguments for pyenv-install" {
|
||||
@test "not enough arguments for pyenv-install if no local version" {
|
||||
stub_python_build
|
||||
stub pyenv-help 'install : true'
|
||||
|
||||
run pyenv-install
|
||||
assert_failure
|
||||
unstub pyenv-help
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "too many arguments for pyenv-install" {
|
||||
@test "multi arguments for pyenv-install" {
|
||||
stub_python_build
|
||||
stub pyenv-help 'install : true'
|
||||
|
||||
run pyenv-install 3.4.1 3.4.2
|
||||
assert_failure
|
||||
unstub pyenv-help
|
||||
assert_success
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "show help for pyenv-install" {
|
||||
|
|
Loading…
Reference in a new issue