mirror of
https://github.com/apisnetworks/pyenv.git
synced 2026-11-30 19:59:01 +00:00
pyenv-uninstall: list installed versions matching a missing version's prefix (#3611)
Middle ground helper due to `pyenv uninstall` not resolving prefixes Co-authored-by: eda-ai-bot <eda-ai-bot@users.noreply.github.com>
This commit is contained in:
1 parent
9b9caf040a
commit
c34a063004
2 files changed
+48
No files matched your search
@@ -63,6 +63,22 @@ IFS=$'\n' scripts=(`pyenv-hooks uninstall`)
|
||||
IFS="$OLDIFS"
|
||||
for script in "${scripts[@]}"; do source "$script"; done
|
||||
|
||||
# List installed versions that the given name is a prefix of
|
||||
# (e.g. 3.7 -> 3.7.14, 3.7-dev) without resolving it, so that the user
|
||||
# can choose the exact version to remove.
|
||||
suggest-installed-versions() {
|
||||
local name="$1"
|
||||
local path candidates=()
|
||||
for path in "${PYENV_ROOT}/versions/${name}".* "${PYENV_ROOT}/versions/${name}"-*; do
|
||||
[ -d "$path" ] && [ ! -L "$path" ] || continue
|
||||
candidates["${#candidates[@]}"]="${path##*/}"
|
||||
done
|
||||
[ "${#candidates[@]}" -gt 0 ] || return 0
|
||||
|
||||
echo "pyenv: installed versions starting with \`$name':"
|
||||
printf ' %s\n' "${candidates[@]}"
|
||||
}
|
||||
|
||||
uninstall-python() {
|
||||
local DEFINITION="$1"
|
||||
|
||||
@@ -72,6 +88,7 @@ uninstall-python() {
|
||||
if [ -z "$FORCE" ]; then
|
||||
if [ ! -d "$PREFIX" ]; then
|
||||
echo "pyenv: version \`$VERSION_NAME' not installed" >&2
|
||||
suggest-installed-versions "$VERSION_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -375,3 +375,34 @@ OUT
|
||||
run head "$(command -v pyenv-uninstall)"
|
||||
assert_output_contains 'Usage: pyenv uninstall'
|
||||
}
|
||||
|
||||
@test "pyenv-uninstall lists installed versions matching a missing version's prefix" {
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.7.1"
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.7.14"
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.7-dev"
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.70.0"
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.8.1"
|
||||
ln -s "${PYENV_ROOT}/versions/3.7.14" "${PYENV_ROOT}/versions/3.7.alias"
|
||||
|
||||
run pyenv-uninstall 3.7
|
||||
|
||||
assert_failure
|
||||
assert_output <<OUT
|
||||
pyenv: version \`3.7' not installed
|
||||
pyenv: installed versions starting with \`3.7':
|
||||
3.7.1
|
||||
3.7.14
|
||||
3.7-dev
|
||||
OUT
|
||||
assert [ -d "${PYENV_ROOT}/versions/3.7.1" ]
|
||||
assert [ -d "${PYENV_ROOT}/versions/3.7.14" ]
|
||||
assert [ -d "${PYENV_ROOT}/versions/3.7-dev" ]
|
||||
}
|
||||
|
||||
@test "pyenv-uninstall reports a missing version without suggestions when nothing matches" {
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.8.1"
|
||||
|
||||
run pyenv-uninstall 3.7
|
||||
|
||||
assert_failure "pyenv: version \`3.7' not installed"
|
||||
}
|
||||
Reference in new issue
Block a user