Explorar el Código

Add support for multiple versions in `pyenv uninstall` (#2432)

pull/2437/head
hardikpnsp hace 3 años
cometido por GitHub
padre
commit
afeb971fa2
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 6 ficheros con 99 adiciones y 38 borrados
  1. +2
    -2
      COMMANDS.md
  2. +1
    -1
      README.md
  3. +3
    -3
      man/man1/pyenv.1
  4. +38
    -28
      plugins/python-build/bin/pyenv-uninstall
  5. +35
    -0
      plugins/python-build/test/hooks.bats
  6. +20
    -4
      plugins/python-build/test/pyenv.bats

+ 2
- 2
COMMANDS.md Ver fichero

@ -238,9 +238,9 @@ To install the latest major release for Python 3 try:
## `pyenv uninstall` ## `pyenv uninstall`
Uninstall a specific Python version.
Uninstall Python versions.
Usage: pyenv uninstall [-f|--force] <version>
Usage: pyenv uninstall [-f|--force] <version> ...
-f Attempt to remove the specified version without prompting -f Attempt to remove the specified version without prompting
for confirmation. If the version does not exist, do not for confirmation. If the version does not exist, do not

+ 1
- 1
README.md Ver fichero

@ -432,7 +432,7 @@ for more details on how the selection works and more information on its usage.
As time goes on, you will accumulate Python versions in your As time goes on, you will accumulate Python versions in your
`$(pyenv root)/versions` directory. `$(pyenv root)/versions` directory.
To remove old Python versions, use [`pyenv uninstall <version>`](COMMANDS.md#pyenv-uninstall).
To remove old Python versions, use [`pyenv uninstall <versions>`](COMMANDS.md#pyenv-uninstall).
Alternatively, you can simply `rm -rf` the directory of the version you want Alternatively, you can simply `rm -rf` the directory of the version you want
to remove. You can find the directory of a particular Python version to remove. You can find the directory of a particular Python version

+ 3
- 3
man/man1/pyenv.1 Ver fichero

@ -106,7 +106,7 @@ Set or show the shell\-specific Python version
List existing pyenv shims List existing pyenv shims
.TP .TP
.B uninstall .B uninstall
Uninstall a specific Python version
Uninstall Python versions
.TP .TP
.B version .B version
Show the current Python version(s) and its origin Show the current Python version(s) and its origin
@ -452,10 +452,10 @@ $ pyenv versions
.fi .fi
.IP "" 0 .IP "" 0
.SS "pyenv uninstall" .SS "pyenv uninstall"
Uninstall a specific Python version\.
Uninstall Python versions\.
.IP "" 4 .IP "" 4
.nf .nf
Usage: pyenv uninstall [\-f|\-\-force] <version>
Usage: pyenv uninstall [\-f|\-\-force] <version> ...
\-f Attempt to remove the specified version without prompting \-f Attempt to remove the specified version without prompting
for confirmation\. If the version does not exist, do not for confirmation\. If the version does not exist, do not

+ 38
- 28
plugins/python-build/bin/pyenv-uninstall Ver fichero

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Summary: Uninstall a specific Python version
# Summary: Uninstall Python versions
# #
# Usage: pyenv uninstall [-f|--force] <version>
# Usage: pyenv uninstall [-f|--force] <version> ...
# #
# -f Attempt to remove the specified version without prompting # -f Attempt to remove the specified version without prompting
# for confirmation. If the version does not exist, do not # for confirmation. If the version does not exist, do not
@ -33,14 +33,17 @@ if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
shift shift
fi fi
[ "$#" -eq 1 ] || usage 1 >&2
[ "$#" -gt 0 ] || usage 1 >&2
DEFINITION="$1"
case "$DEFINITION" in
"" | -* )
usage 1 >&2
;;
esac
versions=("$@")
for version in "${versions[@]}"; do
case "$version" in
"" | -* )
usage 1 >&2
;;
esac
done
declare -a before_hooks after_hooks declare -a before_hooks after_hooks
@ -59,29 +62,36 @@ IFS=$'\n' scripts=(`pyenv-hooks uninstall`)
IFS="$OLDIFS" IFS="$OLDIFS"
for script in "${scripts[@]}"; do source "$script"; done for script in "${scripts[@]}"; do source "$script"; done
uninstall-python() {
local DEFINITION="$1"
VERSION_NAME="${DEFINITION##*/}"
PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
local VERSION_NAME="${DEFINITION##*/}"
local PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
if [ -z "$FORCE" ]; then
if [ ! -d "$PREFIX" ]; then
echo "pyenv: version \`$VERSION_NAME' not installed" >&2
exit 1
if [ -z "$FORCE" ]; then
if [ ! -d "$PREFIX" ]; then
echo "pyenv: version \`$VERSION_NAME' not installed" >&2
exit 1
fi
read -p "pyenv: remove $PREFIX? [y|N] "
case "$REPLY" in
y | Y | yes | YES ) ;;
* ) exit 1 ;;
esac
fi fi
read -p "pyenv: remove $PREFIX? [y|N] "
case "$REPLY" in
y | Y | yes | YES ) ;;
* ) exit 1 ;;
esac
fi
for hook in "${before_hooks[@]}"; do eval "$hook"; done
for hook in "${before_hooks[@]}"; do eval "$hook"; done
if [ -d "$PREFIX" ]; then
rm -rf "$PREFIX"
pyenv-rehash
echo "pyenv: $VERSION_NAME uninstalled"
fi
if [ -d "$PREFIX" ]; then
rm -rf "$PREFIX"
pyenv-rehash
echo "pyenv: $VERSION_NAME uninstalled"
fi
for hook in "${after_hooks[@]}"; do eval "$hook"; done
}
for hook in "${after_hooks[@]}"; do eval "$hook"; done
for version in "${versions[@]}"; do
uninstall-python "$version"
done

+ 35
- 0
plugins/python-build/test/hooks.bats Ver fichero

@ -55,3 +55,38 @@ OUT
refute [ -d "${PYENV_ROOT}/versions/3.6.2" ] refute [ -d "${PYENV_ROOT}/versions/3.6.2" ]
} }
@test "pyenv-uninstall hooks with multiple versions" {
cat > "${HOOK_PATH}/uninstall.bash" <<OUT
before_uninstall 'echo before: \$PREFIX'
after_uninstall 'echo after.'
rm() {
echo "rm \$@"
command rm "\$@"
}
OUT
stub pyenv-hooks "uninstall : echo '$HOOK_PATH'/uninstall.bash"
stub pyenv-rehash "echo rehashed"
stub pyenv-rehash "echo rehashed"
mkdir -p "${PYENV_ROOT}/versions/3.6.2"
mkdir -p "${PYENV_ROOT}/versions/3.6.3"
run pyenv-uninstall -f 3.6.2 3.6.3
assert_success
assert_output <<-OUT
before: ${PYENV_ROOT}/versions/3.6.2
rm -rf ${PYENV_ROOT}/versions/3.6.2
rehashed
pyenv: 3.6.2 uninstalled
after.
before: ${PYENV_ROOT}/versions/3.6.3
rm -rf ${PYENV_ROOT}/versions/3.6.3
rehashed
pyenv: 3.6.3 uninstalled
after.
OUT
refute [ -d "${PYENV_ROOT}/versions/3.6.2" ]
refute [ -d "${PYENV_ROOT}/versions/3.6.3" ]
}

+ 20
- 4
plugins/python-build/test/pyenv.bats Ver fichero

@ -195,12 +195,28 @@ OUT
unstub pyenv-help unstub pyenv-help
} }
@test "too many arguments for pyenv-uninstall" {
stub pyenv-help 'uninstall : true'
@test "more than one argument for pyenv-uninstall" {
mkdir -p "${PYENV_ROOT}/versions/3.4.1"
mkdir -p "${PYENV_ROOT}/versions/3.4.2"
run pyenv-uninstall -f 3.4.1 3.4.2
assert_success
refute [ -d "${PYENV_ROOT}/versions/3.4.1" ]
refute [ -d "${PYENV_ROOT}/versions/3.4.2" ]
}
run pyenv-uninstall 3.4.1 3.4.2
@test "invalid arguments for pyenv-uninstall" {
mkdir -p "${PYENV_ROOT}/versions/3.10.3"
mkdir -p "${PYENV_ROOT}/versions/3.10.4"
run pyenv-uninstall -f 3.10.3 --invalid-option 3.10.4
assert_failure assert_failure
unstub pyenv-help
assert [ -d "${PYENV_ROOT}/versions/3.10.3" ]
assert [ -d "${PYENV_ROOT}/versions/3.10.4" ]
rmdir "${PYENV_ROOT}/versions/3.10.3"
rmdir "${PYENV_ROOT}/versions/3.10.4"
} }
@test "show help for pyenv-uninstall" { @test "show help for pyenv-uninstall" {

Cargando…
Cancelar
Guardar