mirror of
https://github.com/pyenv/pyenv.git
synced 2026-01-24 13:27:27 +09:00
pyenv launcher: introduce and export _PYENV_INSTALL_PREFIX (#3334)
provides a reliable way for Pyenv code to locate other parts of Pyenv code that are not under `PYENV_ROOT` * tests: Work with Git entirely in a test repo Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
This commit is contained in:
parent
aa6c9b9694
commit
2c38423a98
@ -76,23 +76,27 @@ export PYENV_DIR
|
|||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
bin_path="$(abs_dirname "$0")"
|
_PYENV_INSTALL_PREFIX="$(abs_dirname "$0")"
|
||||||
for plugin_bin in "${bin_path%/*}"/plugins/*/bin; do
|
_PYENV_INSTALL_PREFIX="${_PYENV_INSTALL_PREFIX%/*}"
|
||||||
|
|
||||||
|
export _PYENV_INSTALL_PREFIX
|
||||||
|
|
||||||
|
for plugin_bin in "${_PYENV_INSTALL_PREFIX}"/plugins/*/bin; do
|
||||||
PATH="${plugin_bin}:${PATH}"
|
PATH="${plugin_bin}:${PATH}"
|
||||||
done
|
done
|
||||||
# PYENV_ROOT can be set to anything, so it may happen to be equal to the base path above,
|
# PYENV_ROOT can be set to anything, so it may happen to be equal to the base path above,
|
||||||
# resulting in duplicate PATH entries
|
# resulting in duplicate PATH entries
|
||||||
if [ "${bin_path%/*}" != "$PYENV_ROOT" ]; then
|
if [ "${_PYENV_INSTALL_PREFIX}" != "$PYENV_ROOT" ]; then
|
||||||
for plugin_bin in "${PYENV_ROOT}"/plugins/*/bin; do
|
for plugin_bin in "${PYENV_ROOT}"/plugins/*/bin; do
|
||||||
PATH="${plugin_bin}:${PATH}"
|
PATH="${plugin_bin}:${PATH}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
export PATH="${bin_path}:${PATH}"
|
export PATH="${_PYENV_INSTALL_PREFIX}/libexec:${PATH}"
|
||||||
|
|
||||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${PYENV_ROOT}/pyenv.d"
|
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${PYENV_ROOT}/pyenv.d"
|
||||||
if [ "${bin_path%/*}" != "$PYENV_ROOT" ]; then
|
if [ "${_PYENV_INSTALL_PREFIX}" != "$PYENV_ROOT" ]; then
|
||||||
# Add pyenv's own `pyenv.d` unless pyenv was cloned to PYENV_ROOT
|
# Add pyenv's own `pyenv.d` unless pyenv was cloned to PYENV_ROOT
|
||||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${bin_path%/*}/pyenv.d"
|
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${_PYENV_INSTALL_PREFIX}/pyenv.d"
|
||||||
fi
|
fi
|
||||||
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:/usr/etc/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
|
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:/usr/etc/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
|
||||||
for plugin_hook in "${PYENV_ROOT}/plugins/"*/etc/pyenv.d; do
|
for plugin_hook in "${PYENV_ROOT}/plugins/"*/etc/pyenv.d; do
|
||||||
|
|||||||
@ -39,6 +39,7 @@ fi
|
|||||||
|
|
||||||
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
|
PYENV_COMMAND_PATH="$(pyenv-which "$PYENV_COMMAND")"
|
||||||
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
|
PYENV_BIN_PATH="${PYENV_COMMAND_PATH%/*}"
|
||||||
|
|
||||||
export PYENV_VERSION
|
export PYENV_VERSION
|
||||||
|
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
|
|||||||
@ -270,7 +270,7 @@ function print_env() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function print_completion() {
|
function print_completion() {
|
||||||
completion="${0%/*/*}/completions/pyenv.${shell}"
|
completion="${_PYENV_INSTALL_PREFIX}/completions/pyenv.${shell}"
|
||||||
if [ -r "$completion" ]; then
|
if [ -r "$completion" ]; then
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
pwsh )
|
pwsh )
|
||||||
|
|||||||
@ -256,7 +256,6 @@ for DEFINITION in "${DEFINITIONS[@]}"; do
|
|||||||
# Display a more helpful message if the definition wasn't found.
|
# Display a more helpful message if the definition wasn't found.
|
||||||
if [ "$STATUS" == "2" ]; then
|
if [ "$STATUS" == "2" ]; then
|
||||||
{ candidates="$(definitions "$DEFINITION")"
|
{ candidates="$(definitions "$DEFINITION")"
|
||||||
here="$(dirname "${0%/*}")/../.."
|
|
||||||
if [ -n "$candidates" ]; then
|
if [ -n "$candidates" ]; then
|
||||||
echo
|
echo
|
||||||
echo "The following versions contain \`$DEFINITION' in the name:"
|
echo "The following versions contain \`$DEFINITION' in the name:"
|
||||||
@ -266,12 +265,13 @@ for DEFINITION in "${DEFINITIONS[@]}"; do
|
|||||||
echo "See all available versions with \`pyenv install --list'."
|
echo "See all available versions with \`pyenv install --list'."
|
||||||
echo
|
echo
|
||||||
echo -n "If the version you need is missing, try upgrading pyenv"
|
echo -n "If the version you need is missing, try upgrading pyenv"
|
||||||
if [ "$here" != "${here#$(brew --prefix 2>/dev/null)}" ]; then
|
declare brew_prefix
|
||||||
|
if brew_prefix="$(brew --prefix 2>/dev/null)" && [[ $_PYENV_INSTALL_PREFIX/ == "$brew_prefix/"* ]]; then
|
||||||
printf ":\n\n"
|
printf ":\n\n"
|
||||||
echo " brew update && brew upgrade pyenv"
|
echo " brew update && brew upgrade pyenv"
|
||||||
elif [ -d "${here}/.git" ]; then
|
elif [ -d "${_PYENV_INSTALL_PREFIX}/.git" ]; then
|
||||||
printf ":\n\n"
|
printf ":\n\n"
|
||||||
echo " cd ${here} && git pull && cd -"
|
echo " cd ${_PYENV_INSTALL_PREFIX} && git pull && cd -"
|
||||||
else
|
else
|
||||||
printf ".\n"
|
printf ".\n"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -140,7 +140,11 @@ OUT
|
|||||||
stub_python_build 'echo ERROR >&2 && exit 2'
|
stub_python_build 'echo ERROR >&2 && exit 2'
|
||||||
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
|
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
|
||||||
|
|
||||||
run pyenv-install 2.7.9
|
mkdir "$BATS_TEST_TMPDIR/.git"
|
||||||
|
#Faking the Pyenv installation prefix may break things.
|
||||||
|
# May have to move some dependent stuff into the fake root for the code to find it
|
||||||
|
# or introduce an overriding test variable in the code specifically for the hint.
|
||||||
|
_PYENV_INSTALL_PREFIX="$BATS_TEST_TMPDIR" run pyenv-install 2.7.9
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
ERROR
|
ERROR
|
||||||
@ -153,19 +157,19 @@ See all available versions with \`pyenv install --list'.
|
|||||||
|
|
||||||
If the version you need is missing, try upgrading pyenv:
|
If the version you need is missing, try upgrading pyenv:
|
||||||
|
|
||||||
cd ${BATS_TEST_DIRNAME}/../../.. && git pull && cd -
|
cd ${BATS_TEST_TMPDIR} && git pull && cd -
|
||||||
OUT
|
OUT
|
||||||
|
|
||||||
unstub python-build
|
unstub python-build
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "homebrew upgrade instructions given when pyenv is homebrew-installed" {
|
@test "homebrew upgrade instructions given when pyenv is homebrew-installed" {
|
||||||
stub brew "--prefix : echo '${BATS_TEST_DIRNAME%/*}'"
|
stub brew "--prefix : echo '${_PYENV_INSTALL_PREFIX}'"
|
||||||
stub_python_build_lib
|
stub_python_build_lib
|
||||||
stub_python_build 'echo ERROR >&2 && exit 2' \
|
stub_python_build 'echo ERROR >&2 && exit 2' \
|
||||||
"--definitions : true"
|
"--definitions : true"
|
||||||
|
|
||||||
run pyenv-install 1.9.3
|
_PYENV_INSTALL_PREFIX="$BATS_TEST_TMPDIR" run pyenv-install 1.9.3
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_output <<OUT
|
assert_output <<OUT
|
||||||
ERROR
|
ERROR
|
||||||
|
|||||||
@ -3,10 +3,11 @@
|
|||||||
load test_helper
|
load test_helper
|
||||||
|
|
||||||
_setup() {
|
_setup() {
|
||||||
export GIT_DIR="${PYENV_TEST_DIR}/.git"
|
export GIT_DIR="${PYENV_TEST_DIR}"
|
||||||
mkdir -p "$HOME"
|
export GIT_WORK_TREE="$GIT_DIR"
|
||||||
git config --global user.name "Tester"
|
git init --quiet
|
||||||
git config --global user.email "tester@test.local"
|
git config user.name "Tester"
|
||||||
|
git config user.email "tester@test.local"
|
||||||
cd "$PYENV_TEST_DIR"
|
cd "$PYENV_TEST_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +23,6 @@ git_commit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "doesn't read version from non-pyenv repo" {
|
@test "doesn't read version from non-pyenv repo" {
|
||||||
git init
|
|
||||||
git remote add origin https://github.com/homebrew/homebrew.git
|
git remote add origin https://github.com/homebrew/homebrew.git
|
||||||
git_commit
|
git_commit
|
||||||
git tag v1.0
|
git tag v1.0
|
||||||
@ -33,7 +33,6 @@ git_commit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "reads version from git repo" {
|
@test "reads version from git repo" {
|
||||||
git init
|
|
||||||
git remote add origin https://github.com/pyenv/pyenv.git
|
git remote add origin https://github.com/pyenv/pyenv.git
|
||||||
git_commit
|
git_commit
|
||||||
git tag v0.4.1
|
git tag v0.4.1
|
||||||
@ -45,7 +44,6 @@ git_commit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "prints default version if no tags in git repo" {
|
@test "prints default version if no tags in git repo" {
|
||||||
git init
|
|
||||||
git remote add origin https://github.com/pyenv/pyenv.git
|
git remote add origin https://github.com/pyenv/pyenv.git
|
||||||
git_commit
|
git_commit
|
||||||
|
|
||||||
|
|||||||
@ -24,10 +24,9 @@ load test_helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "setup shell completions" {
|
@test "setup shell completions" {
|
||||||
exec_root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
|
||||||
run pyenv-init - bash
|
run pyenv-init - bash
|
||||||
assert_success
|
assert_success
|
||||||
assert_line "source '${exec_root}/completions/pyenv.bash'"
|
assert_line "source '${_PYENV_INSTALL_PREFIX}/completions/pyenv.bash'"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "detect parent shell" {
|
@test "detect parent shell" {
|
||||||
@ -50,10 +49,9 @@ OUT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "setup shell completions (fish)" {
|
@test "setup shell completions (fish)" {
|
||||||
exec_root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
|
||||||
run pyenv-init - fish
|
run pyenv-init - fish
|
||||||
assert_success
|
assert_success
|
||||||
assert_line "source '${exec_root}/completions/pyenv.fish'"
|
assert_line "source '${_PYENV_INSTALL_PREFIX}/completions/pyenv.fish'"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "fish instructions" {
|
@test "fish instructions" {
|
||||||
|
|||||||
@ -2,8 +2,9 @@ unset PYENV_VERSION
|
|||||||
unset PYENV_DIR
|
unset PYENV_DIR
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
export _PYENV_INSTALL_PREFIX="${BATS_TEST_DIRNAME%/*}"
|
||||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||||
if ! enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
|
if ! enable -f "${_PYENV_INSTALL_PREFIX}"/libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
|
||||||
if [ -n "$PYENV_NATIVE_EXT" ]; then
|
if [ -n "$PYENV_NATIVE_EXT" ]; then
|
||||||
echo "pyenv: failed to load \`realpath' builtin" >&2
|
echo "pyenv: failed to load \`realpath' builtin" >&2
|
||||||
exit 1
|
exit 1
|
||||||
@ -25,7 +26,7 @@ setup() {
|
|||||||
|
|
||||||
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
||||||
PATH="${PYENV_TEST_DIR}/bin:$PATH"
|
PATH="${PYENV_TEST_DIR}/bin:$PATH"
|
||||||
PATH="${BATS_TEST_DIRNAME%/*}/libexec:$PATH"
|
PATH="${_PYENV_INSTALL_PREFIX}/libexec:$PATH"
|
||||||
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
|
PATH="${BATS_TEST_DIRNAME}/libexec:$PATH"
|
||||||
PATH="${PYENV_ROOT}/shims:$PATH"
|
PATH="${PYENV_ROOT}/shims:$PATH"
|
||||||
PATH="${BATS_TEST_TMPDIR}/stubs:$PATH"
|
PATH="${BATS_TEST_TMPDIR}/stubs:$PATH"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user