mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
pyenv-latest: replace -q with -b and -f, document as internal
More tailored for the emergent internal use cases
This commit is contained in:
parent
88f76ee787
commit
9373970678
7 changed files with 48 additions and 14 deletions
|
@ -1,9 +1,11 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Summary: Print the latest installed or known version with the given prefix
|
# Summary: Print the latest installed or known version with the given prefix
|
||||||
# Usage: pyenv latest [-k|--known] [-q|--quiet] <prefix>
|
# Usage: pyenv latest [-k|--known] <prefix>
|
||||||
#
|
#
|
||||||
# -k/--known Select from all known versions instead of installed
|
# -k/--known Select from all known versions instead of installed
|
||||||
# -q/--quiet Do not print an error message on resolution failure
|
# -b/--bypass (internal) On a resolution failure, do not print an error message
|
||||||
|
# but rather print the argument unchanged
|
||||||
|
# -f/--force (internal) Same as -b but also do not return a failure exit code
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
@ -15,8 +17,13 @@ do
|
||||||
FROM_KNOWN=1
|
FROM_KNOWN=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-q|--quiet)
|
-b|--bypass)
|
||||||
QUIET=1
|
BYPASS=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-f|--force)
|
||||||
|
FORCE=1
|
||||||
|
BYPASS=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -71,10 +78,14 @@ IFS=$'\n'
|
||||||
if [[ -n "$DEFINITION" ]]; then
|
if [[ -n "$DEFINITION" ]]; then
|
||||||
echo "$DEFINITION"
|
echo "$DEFINITION"
|
||||||
else
|
else
|
||||||
if [[ -z $QUIET ]]; then
|
if [[ -z $BYPASS ]]; then
|
||||||
echo "pyenv: no $([[ -z $FROM_KNOWN ]] && echo installed || echo known) versions match the prefix \`$prefix'" >&2
|
echo "pyenv: no $([[ -z $FROM_KNOWN ]] && echo installed || echo known) versions match the prefix \`$prefix'" >&2
|
||||||
|
else
|
||||||
|
echo "$prefix"
|
||||||
|
fi
|
||||||
|
if [[ -z $FORCE ]]; then
|
||||||
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
exitcode=1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit $exitcode
|
exit $exitcode
|
||||||
|
|
|
@ -42,7 +42,7 @@ OLDIFS="$IFS"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
version="$(pyenv-latest -q "$version" || echo "$version")"
|
version="$(pyenv-latest -f "$version")"
|
||||||
PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}"
|
PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}"
|
||||||
fi
|
fi
|
||||||
if [ -d "$PYENV_PREFIX_PATH" ]; then
|
if [ -d "$PYENV_PREFIX_PATH" ]; then
|
||||||
|
|
|
@ -34,7 +34,7 @@ OLDIFS="$IFS"
|
||||||
versions=("${versions[@]}" "${version}")
|
versions=("${versions[@]}" "${version}")
|
||||||
elif version_exists "${version#python-}"; then
|
elif version_exists "${version#python-}"; then
|
||||||
versions=("${versions[@]}" "${version#python-}")
|
versions=("${versions[@]}" "${version#python-}")
|
||||||
elif resolved_version="$(pyenv-latest -q "$version")"; then
|
elif resolved_version="$(pyenv-latest -b "$version")"; then
|
||||||
versions=("${versions[@]}" "${resolved_version}")
|
versions=("${versions[@]}" "${resolved_version}")
|
||||||
else
|
else
|
||||||
echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
|
echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
|
||||||
|
|
|
@ -158,7 +158,7 @@ for DEFINITION in "${DEFINITIONS[@]}"; do
|
||||||
# Try to resolve a prefix if user indeed gave a prefix.
|
# Try to resolve a prefix if user indeed gave a prefix.
|
||||||
# We install the version under the resolved name
|
# We install the version under the resolved name
|
||||||
# and hooks also see the resolved name
|
# and hooks also see the resolved name
|
||||||
DEFINITION="$(pyenv-latest -q -k "$DEFINITION" || echo "$DEFINITION")"
|
DEFINITION="$(pyenv-latest -f -k "$DEFINITION")"
|
||||||
|
|
||||||
# Set VERSION_NAME from $DEFINITION. Then compute the installation prefix.
|
# Set VERSION_NAME from $DEFINITION. Then compute the installation prefix.
|
||||||
VERSION_NAME="${DEFINITION##*/}"
|
VERSION_NAME="${DEFINITION##*/}"
|
||||||
|
|
|
@ -15,9 +15,10 @@ after_install 'echo after: \$STATUS'
|
||||||
OUT
|
OUT
|
||||||
stub pyenv-hooks "install : echo '$HOOK_PATH'/install.bash"
|
stub pyenv-hooks "install : echo '$HOOK_PATH'/install.bash"
|
||||||
stub pyenv-rehash "echo rehashed"
|
stub pyenv-rehash "echo rehashed"
|
||||||
stub pyenv-latest false
|
|
||||||
|
|
||||||
definition="${TMP}/3.6.2"
|
definition="${TMP}/3.6.2"
|
||||||
|
stub pyenv-latest "echo $definition"
|
||||||
|
|
||||||
cat > "$definition" <<<"echo python-build"
|
cat > "$definition" <<<"echo python-build"
|
||||||
run pyenv-install "$definition"
|
run pyenv-install "$definition"
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ stub_python_build_no_latest() {
|
||||||
|
|
||||||
stub_python_build() {
|
stub_python_build() {
|
||||||
stub_python_build_no_latest "$@"
|
stub_python_build_no_latest "$@"
|
||||||
stub pyenv-latest false
|
stub pyenv-latest '-f -k * : shift 2; echo "$@"'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "install a single version" {
|
@test "install a single version" {
|
||||||
|
@ -65,9 +65,9 @@ OUT
|
||||||
stub_python_build_lib
|
stub_python_build_lib
|
||||||
for i in {1..3}; do stub_python_build_no_latest; done
|
for i in {1..3}; do stub_python_build_no_latest; done
|
||||||
stub pyenv-latest \
|
stub pyenv-latest \
|
||||||
'-q -k 3.4 : echo 3.4.2' \
|
'-r -k 3.4 : echo 3.4.2' \
|
||||||
'-q -k 3.5.1 : false' \
|
'-r -k 3.5.1 : false' \
|
||||||
'-q -k 3.5 : echo 3.5.2'
|
'-r -k 3.5 : echo 3.5.2'
|
||||||
|
|
||||||
run pyenv-install 3.4 3.5.1 3.5
|
run pyenv-install 3.4 3.5.1 3.5
|
||||||
assert_success <<OUT
|
assert_success <<OUT
|
||||||
|
|
|
@ -115,3 +115,25 @@ echo 3.8.1/envs/foo
|
||||||
3.8.1
|
3.8.1
|
||||||
!
|
!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "falls back to argument with -b" {
|
||||||
|
create_executable pyenv-versions <<!
|
||||||
|
#!$BASH
|
||||||
|
!
|
||||||
|
run pyenv-latest -b nonexistent
|
||||||
|
assert_failure
|
||||||
|
assert_output <<!
|
||||||
|
nonexistent
|
||||||
|
!
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "falls back to argument and succeeds with -f" {
|
||||||
|
create_executable pyenv-versions <<!
|
||||||
|
#!$BASH
|
||||||
|
!
|
||||||
|
run pyenv-latest -f nonexistent
|
||||||
|
assert_success
|
||||||
|
assert_output <<!
|
||||||
|
nonexistent
|
||||||
|
!
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue