mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-22 20:23:41 +00:00
commit
948d1f4ca7
3 changed files with 31 additions and 2 deletions
|
@ -54,6 +54,19 @@ 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
|
||||
fi
|
||||
|
||||
if [ -z "${PYENV_DIR}" ]; then
|
||||
PYENV_DIR="$(pwd)"
|
||||
else
|
||||
|
|
|
@ -46,13 +46,13 @@ set -e
|
|||
[ -n "\$PYENV_DEBUG" ] && set -x
|
||||
|
||||
program="\${0##*/}"
|
||||
if [ "\$program" = "python" ]; then
|
||||
if [[ "\$program" = "python"* ]]; then
|
||||
for arg; do
|
||||
case "\$arg" in
|
||||
-c* | -- ) break ;;
|
||||
*/* )
|
||||
if [ -f "\$arg" ]; then
|
||||
export PYENV_DIR="\${arg%/*}"
|
||||
export PYENV_FILE_ARG="\$arg"
|
||||
break
|
||||
fi
|
||||
;;
|
||||
|
|
|
@ -12,3 +12,19 @@ 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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue