Show symlink contents in non-bare `pyenv versions' (#2609)

* Change other tests to use the newly-created convenience function
This commit is contained in:
native-api 2023-02-02 17:24:19 +03:00 committed by GitHub
parent 368e04f3fa
commit 9248255f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 10 deletions

View file

@ -104,10 +104,19 @@ exists() {
}
print_version() {
local version="${1:?}"
local path="${2:?}"
if [[ -z "$bare" && -L "$path" ]]; then
# Only resolve the link itself for printing, do not resolve further.
# Doing otherwise would misinform the user of what the link contains.
version_repr="$version --> $(resolve_link "$version")"
else
version_repr="$version"
fi
if [[ ${BASH_VERSINFO[0]} -ge 4 && ${current_versions["$1"]} ]]; then
echo "${hit_prefix}$1 (set by $(pyenv-version-origin))"
echo "${hit_prefix}${version_repr} (set by $(pyenv-version-origin))"
elif (( ${BASH_VERSINFO[0]} <= 3 )) && exists "$1" "${current_versions[@]}"; then
echo "${hit_prefix}$1 (set by $(pyenv-version-origin))"
echo "${hit_prefix}${version_repr} (set by $(pyenv-version-origin))"
else
echo "${miss_prefix}$1"
fi
@ -119,7 +128,7 @@ if [ -n "$include_system" ] && \
(PYENV_VERSION=system pyenv-which python >/dev/null 2>&1 || \
PYENV_VERSION=system pyenv-which python3 >/dev/null 2>&1 || \
PYENV_VERSION=system pyenv-which python2 >/dev/null 2>&1) ; then
print_version system
print_version system "/"
fi
shopt -s dotglob nullglob
@ -139,14 +148,14 @@ for path in "${versions_dir_entries[@]}"; do
if [ -d "$path" ]; then
if [ -n "$skip_aliases" ] && [ -L "$path" ]; then
target="$(realpath "$path")"
[ "${target%/*}" != "$versions_dir" ] || continue
[ "${target%/*/envs/*}" != "$versions_dir" ] || continue
[ "${target%/*}" == "$versions_dir" ] && continue
[ "${target%/*/envs/*}" == "$versions_dir" ] && continue
fi
print_version "${path##*/}"
print_version "${path##*/}" "$path"
# virtual environments created by anaconda/miniconda
for env_path in "${path}/envs/"*; do
if [ -d "${env_path}" ]; then
print_version "${env_path#${PYENV_ROOT}/versions/}"
print_version "${env_path#${PYENV_ROOT}/versions/}" "${env_path}"
fi
done
fi

View file

@ -6,6 +6,11 @@ create_version() {
mkdir -p "${PYENV_ROOT}/versions/$1"
}
create_alias() {
mkdir -p "${PYENV_ROOT}/versions"
ln -s "$2" "${PYENV_ROOT}/versions/$1"
}
setup() {
mkdir -p "$PYENV_TEST_DIR"
cd "$PYENV_TEST_DIR"
@ -138,7 +143,7 @@ OUT
@test "lists symlinks under versions" {
create_version "2.7.8"
ln -s "2.7.8" "${PYENV_ROOT}/versions/2.7"
create_alias "2.7" "2.7.8"
run pyenv-versions --bare
assert_success
@ -150,9 +155,9 @@ OUT
@test "doesn't list symlink aliases when --skip-aliases" {
create_version "1.8.7"
ln -s "1.8.7" "${PYENV_ROOT}/versions/1.8"
create_alias "1.8" "1.8.7"
mkdir moo
ln -s "${PWD}/moo" "${PYENV_ROOT}/versions/1.9"
create_alias "1.9" "${PWD}/moo"
run pyenv-versions --bare --skip-aliases
assert_success
@ -210,3 +215,14 @@ SH
1.9.0
OUT
}
@test "non-bare output resolves links" {
create_version "1.9.0"
create_alias "link" "foo/bar"
run pyenv-versions
assert_success <<OUT
1.9.0
link --> foo/bar
OUT
}