mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-10 12:33:48 -05:00
Auto-resolve prefixes to the latest version (#2487)
This commit is contained in:
@@ -60,11 +60,30 @@ NUM_DEFINITIONS="$(find "$BATS_TEST_DIRNAME"/../share/python-build -maxdepth 1 -
|
||||
}
|
||||
|
||||
@test "installing nonexistent definition" {
|
||||
stub pyenv-latest false
|
||||
run python-build "nonexistent" "${TMP}/install"
|
||||
assert [ "$status" -eq 2 ]
|
||||
assert_output "python-build: definition not found: nonexistent"
|
||||
}
|
||||
|
||||
@test "resolves prefixes via pyenv-latest" {
|
||||
stub pyenv-latest "echo 2.7.8"
|
||||
export PYTHON_BUILD_ROOT="$TMP"
|
||||
mkdir -p "${PYTHON_BUILD_ROOT}/share/python-build"
|
||||
echo 'echo 2.7.8' > "${PYTHON_BUILD_ROOT}/share/python-build/2.7.8"
|
||||
run python-build "2.7" "${TMP}/install"
|
||||
assert_success "2.7.8"
|
||||
}
|
||||
|
||||
@test "doesn't resolve prefixes if pyenv-latest is unavailable" {
|
||||
export PATH="$(path_without pyenv-latest)"
|
||||
export PYTHON_BUILD_ROOT="$TMP"
|
||||
mkdir -p "${PYTHON_BUILD_ROOT}/share/python-build"
|
||||
echo 'echo 2.7.8' > "${PYTHON_BUILD_ROOT}/share/python-build/2.7.8"
|
||||
run python-build "2.7" "${TMP}/install"
|
||||
assert_failure "python-build: definition not found: 2.7"
|
||||
}
|
||||
|
||||
@test "sorting Python versions" {
|
||||
export PYTHON_BUILD_ROOT="$TMP"
|
||||
mkdir -p "${PYTHON_BUILD_ROOT}/share/python-build"
|
||||
|
||||
@@ -15,6 +15,7 @@ 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"
|
||||
cat > "$definition" <<<"echo python-build"
|
||||
|
||||
@@ -10,6 +10,7 @@ setup() {
|
||||
|
||||
stub_python_build() {
|
||||
stub python-build "--lib : $BATS_TEST_DIRNAME/../bin/python-build --lib" "$@"
|
||||
stub pyenv-latest " : false"
|
||||
}
|
||||
|
||||
@test "install proper" {
|
||||
@@ -23,6 +24,19 @@ stub_python_build() {
|
||||
unstub pyenv-rehash
|
||||
}
|
||||
|
||||
@test "install resolves a prefix" {
|
||||
stub_python_build 'echo python-build "$@"'
|
||||
stub pyenv-latest '-q -k 3.4 : echo 3.4.2'
|
||||
pyenv-latest || true # pass through the stub entry added by stub_python_build
|
||||
|
||||
run pyenv-install 3.4
|
||||
assert_success "python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2"
|
||||
|
||||
unstub python-build
|
||||
unstub pyenv-hooks
|
||||
unstub pyenv-rehash
|
||||
}
|
||||
|
||||
@test "install pyenv local version by default" {
|
||||
stub_python_build 'echo python-build "$1"'
|
||||
stub pyenv-local 'echo 3.4.2'
|
||||
|
||||
@@ -139,3 +139,29 @@ assert_output_contains() {
|
||||
} | flunk
|
||||
}
|
||||
}
|
||||
|
||||
# Output a modified PATH that ensures that the given executable is not present,
|
||||
# but in which system utils necessary for pyenv operation are still available.
|
||||
path_without() {
|
||||
local path=":${PATH}:"
|
||||
for exe; do
|
||||
local found alt util
|
||||
for found in $(PATH="$path" type -aP "$exe"); do
|
||||
found="${found%/*}"
|
||||
if [ "$found" != "${PYENV_ROOT}/shims" ]; then
|
||||
alt="${PYENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')"
|
||||
mkdir -p "$alt"
|
||||
for util in bash head cut readlink greadlink; do
|
||||
if [ -x "${found}/$util" ]; then
|
||||
ln -s "${found}/$util" "${alt}/$util"
|
||||
fi
|
||||
done
|
||||
path="${path/:${found}:/:${alt}:}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
path="${path#:}"
|
||||
path="${path%:}"
|
||||
echo "$path"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user