From 9373970678f48dd7e86348e428269930d0645cb0 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Sat, 20 Jul 2024 22:06:13 +0300 Subject: [PATCH 1/2] pyenv-latest: replace -q with -b and -f, document as internal More tailored for the emergent internal use cases --- libexec/pyenv-latest | 23 +++++++++++++++++------ libexec/pyenv-prefix | 2 +- libexec/pyenv-version-name | 2 +- plugins/python-build/bin/pyenv-install | 2 +- plugins/python-build/test/hooks.bats | 3 ++- plugins/python-build/test/pyenv.bats | 8 ++++---- test/latest.bats | 22 ++++++++++++++++++++++ 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/libexec/pyenv-latest b/libexec/pyenv-latest index 6f2d9e97..330e1e29 100755 --- a/libexec/pyenv-latest +++ b/libexec/pyenv-latest @@ -1,9 +1,11 @@ #!/usr/bin/env bash # Summary: Print the latest installed or known version with the given prefix -# Usage: pyenv latest [-k|--known] [-q|--quiet] +# Usage: pyenv latest [-k|--known] # # -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 [ -n "$PYENV_DEBUG" ] && set -x @@ -15,8 +17,13 @@ do FROM_KNOWN=1 shift ;; - -q|--quiet) - QUIET=1 + -b|--bypass) + BYPASS=1 + shift + ;; + -f|--force) + FORCE=1 + BYPASS=1 shift ;; *) @@ -71,10 +78,14 @@ IFS=$'\n' if [[ -n "$DEFINITION" ]]; then echo "$DEFINITION" 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 + else + echo "$prefix" + fi + if [[ -z $FORCE ]]; then + exitcode=1 fi - exitcode=1 fi exit $exitcode diff --git a/libexec/pyenv-prefix b/libexec/pyenv-prefix index 261b865f..65bc5425 100755 --- a/libexec/pyenv-prefix +++ b/libexec/pyenv-prefix @@ -42,7 +42,7 @@ OLDIFS="$IFS" exit 1 fi else - version="$(pyenv-latest -q "$version" || echo "$version")" + version="$(pyenv-latest -f "$version")" PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}" fi if [ -d "$PYENV_PREFIX_PATH" ]; then diff --git a/libexec/pyenv-version-name b/libexec/pyenv-version-name index d06357cb..52d7f8d7 100755 --- a/libexec/pyenv-version-name +++ b/libexec/pyenv-version-name @@ -34,7 +34,7 @@ OLDIFS="$IFS" versions=("${versions[@]}" "${version}") elif version_exists "${version#python-}"; then versions=("${versions[@]}" "${version#python-}") - elif resolved_version="$(pyenv-latest -q "$version")"; then + elif resolved_version="$(pyenv-latest -b "$version")"; then versions=("${versions[@]}" "${resolved_version}") else echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2 diff --git a/plugins/python-build/bin/pyenv-install b/plugins/python-build/bin/pyenv-install index 2d5c356b..778489b7 100755 --- a/plugins/python-build/bin/pyenv-install +++ b/plugins/python-build/bin/pyenv-install @@ -158,7 +158,7 @@ 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")" + DEFINITION="$(pyenv-latest -f -k "$DEFINITION")" # Set VERSION_NAME from $DEFINITION. Then compute the installation prefix. VERSION_NAME="${DEFINITION##*/}" diff --git a/plugins/python-build/test/hooks.bats b/plugins/python-build/test/hooks.bats index 03289524..1c3ec343 100644 --- a/plugins/python-build/test/hooks.bats +++ b/plugins/python-build/test/hooks.bats @@ -15,9 +15,10 @@ after_install 'echo after: \$STATUS' OUT stub pyenv-hooks "install : echo '$HOOK_PATH'/install.bash" stub pyenv-rehash "echo rehashed" - stub pyenv-latest false definition="${TMP}/3.6.2" + stub pyenv-latest "echo $definition" + cat > "$definition" <<<"echo python-build" run pyenv-install "$definition" diff --git a/plugins/python-build/test/pyenv.bats b/plugins/python-build/test/pyenv.bats index 1ca82706..e521201c 100644 --- a/plugins/python-build/test/pyenv.bats +++ b/plugins/python-build/test/pyenv.bats @@ -18,7 +18,7 @@ stub_python_build_no_latest() { stub_python_build() { stub_python_build_no_latest "$@" - stub pyenv-latest false + stub pyenv-latest '-f -k * : shift 2; echo "$@"' } @test "install a single version" { @@ -65,9 +65,9 @@ OUT stub_python_build_lib for i in {1..3}; do stub_python_build_no_latest; done stub pyenv-latest \ - '-q -k 3.4 : echo 3.4.2' \ - '-q -k 3.5.1 : false' \ - '-q -k 3.5 : echo 3.5.2' + '-r -k 3.4 : echo 3.4.2' \ + '-r -k 3.5.1 : false' \ + '-r -k 3.5 : echo 3.5.2' run pyenv-install 3.4 3.5.1 3.5 assert_success < Date: Sun, 21 Jul 2024 06:30:27 +0300 Subject: [PATCH 2/2] Remove nop tests Easy syncing with Rbenv is not as important now --- plugins/python-build/test/build.bats | 48 ---------------------------- 1 file changed, 48 deletions(-) diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index aacef79f..3a1e4e6f 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -888,54 +888,6 @@ OUT assert_success "hello world" } -@test "mruby strategy overwrites non-writable files" { - # nop -} - -@test "mruby strategy fetches rake if missing" { - # nop -} - -@test "rbx uses bundle then rake" { - # nop -} - -@test "fixes rbx binstubs" { - # nop -} - -@test "JRuby build" { - # nop -} - -@test "JRuby+Graal does not install launchers" { - # nop -} - -@test "JRuby Java 7 missing" { - # nop -} - -@test "JRuby Java is outdated" { - # nop -} - -@test "JRuby Java 7 up-to-date" { - # nop -} - -@test "Java version string not on first line" { - # nop -} - -@test "Java version string on OpenJDK" { - # nop -} - -@test "JRuby Java 9 version string" { - # nop -} - @test "non-writable TMPDIR aborts build" { export TMPDIR="${TMP}/build" mkdir -p "$TMPDIR"