From e44490c63929c7f2f88d0d216cbaba4bbbf22d3e Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Tue, 16 Feb 2021 23:46:08 +0300 Subject: [PATCH 1/3] Revert "add tests for `PYENV_FILE_ARG`" This reverts commit 438e828eb507536eebe42adee3e896bceb165d8c. # Conflicts: # test/pyenv_ext.bats --- test/pyenv_ext.bats | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/test/pyenv_ext.bats b/test/pyenv_ext.bats index 4a3a4a8f..cc138cbe 100644 --- a/test/pyenv_ext.bats +++ b/test/pyenv_ext.bats @@ -12,28 +12,3 @@ load test_helper PYENV_VERSION="2.7.10:system" run pyenv-prefix assert_success "${PYENV_ROOT}/versions/2.7.10:${PYENV_TEST_DIR}" } - -@test "should use dirname of file argument as PYENV_DIR" { - mkdir -p "${PYENV_TEST_DIR}/dir1" - touch "${PYENV_TEST_DIR}/dir1/file.py" - PYENV_FILE_ARG="${PYENV_TEST_DIR}/dir1/file.py" run pyenv echo PYENV_DIR - assert_output "${PYENV_TEST_DIR}/dir1" -} - -@test "should follow symlink of file argument (#379, #404)" { - mkdir -p "${PYENV_TEST_DIR}/dir1" - mkdir -p "${PYENV_TEST_DIR}/dir2" - touch "${PYENV_TEST_DIR}/dir1/file.py" - ln -s "${PYENV_TEST_DIR}/dir1/file.py" "${PYENV_TEST_DIR}/dir2/symlink.py" - PYENV_FILE_ARG="${PYENV_TEST_DIR}/dir2/symlink.py" run pyenv echo PYENV_DIR - assert_output "${PYENV_TEST_DIR}/dir1" -} - -@test "should handle relative symlinks for file argument (#580)" { - mkdir -p "${PYENV_TEST_DIR}" - cd "${PYENV_TEST_DIR}" - touch file.py - ln -s file.py symlink.py - PYENV_FILE_ARG="symlink.py" run pyenv echo PYENV_DIR - assert_output "${PYENV_TEST_DIR}" -} From a6b0a2846ee62da74b95bee2fca1d4c1f60eb979 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Tue, 16 Feb 2021 23:53:05 +0300 Subject: [PATCH 2/3] Revert "shims: handle symlinked scripts, via new PYENV_FILE_ARG" This reverts commit 493f036928b8ed9e456b2112475973e23b1ec330. # Conflicts: # libexec/pyenv --- libexec/pyenv | 18 ------------------ libexec/pyenv-rehash | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/libexec/pyenv b/libexec/pyenv index 93debeae..4d1a6c58 100755 --- a/libexec/pyenv +++ b/libexec/pyenv @@ -61,24 +61,6 @@ else fi export PYENV_ROOT -# Transfer PYENV_FILE_ARG (from shims) into PYENV_DIR. -if [ -z "${PYENV_DIR}" ]; then - if [ -n "${PYENV_FILE_ARG}" ]; then - if [ -L "${PYENV_FILE_ARG}" ]; then - PYENV_DIR="$(abs_dirname "${PYENV_FILE_ARG}")" - else - PYENV_DIR="${PYENV_FILE_ARG%/*}" - fi - export PYENV_DIR - unset PYENV_FILE_ARG - fi -else - [[ $PYENV_DIR == /* ]] || PYENV_DIR="$PWD/$PYENV_DIR" - cd "$PYENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$PYENV_DIR'" - PYENV_DIR="$PWD" - cd "$OLDPWD" -fi - if [ -z "${PYENV_DIR}" ]; then PYENV_DIR="$PWD" fi diff --git a/libexec/pyenv-rehash b/libexec/pyenv-rehash index 5c421c41..094d6173 100755 --- a/libexec/pyenv-rehash +++ b/libexec/pyenv-rehash @@ -73,7 +73,7 @@ if [[ "\$program" = "python"* ]]; then -c* | -- ) break ;; */* ) if [ -f "\$arg" ]; then - export PYENV_FILE_ARG="\$arg" + export PYENV_DIR="\${arg%/*}" break fi ;; From 131e44afcbe7ea09ae9f4e3f460ae8f19574507f Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Tue, 16 Feb 2021 23:59:08 +0300 Subject: [PATCH 3/3] Remove the "Using script's directory as PYENV_DIR if shim is invoked with a script argument" feature It's impossible to 100% reliably extract the script argument from the command line for all and unknown Python versions and implementations --- libexec/pyenv-rehash | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libexec/pyenv-rehash b/libexec/pyenv-rehash index 094d6173..5fcb6646 100755 --- a/libexec/pyenv-rehash +++ b/libexec/pyenv-rehash @@ -67,19 +67,6 @@ set -e [ -n "\$PYENV_DEBUG" ] && set -x program="\${0##*/}" -if [[ "\$program" = "python"* ]]; then - for arg; do - case "\$arg" in - -c* | -- ) break ;; - */* ) - if [ -f "\$arg" ]; then - export PYENV_DIR="\${arg%/*}" - break - fi - ;; - esac - done -fi export PYENV_ROOT="$PYENV_ROOT" exec "$(command -v pyenv)" exec "\$program" "\$@"