install-prerequisites: add an option for optional dependencies (#3560)

This commit is contained in:
native-api 2026-09-24 00:12:25 +03:00 committed by GitHub
parent 26370b7f24
commit a3c666e177
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 14 deletions

View File

@ -2,13 +2,16 @@
# #
# Summary: Install Python build prerequisites on Debian-based systems # Summary: Install Python build prerequisites on Debian-based systems
# #
# Usage: pyenv install-prerequisites # Usage: pyenv install-prerequisites [-a|--all]
#
# -a/--all Also install optional dependencies (for rarely used modules)
# #
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions # Provide pyenv completions
if [ "$1" = "--complete" ]; then if [ "$1" = "--complete" ]; then
echo --all
exit exit
fi fi
@ -17,11 +20,22 @@ usage() {
[ -z "$1" ] || exit "$1" [ -z "$1" ] || exit "$1"
} }
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then all=
usage 0
fi
[ "$#" -eq 0 ] || usage 1 >&2 while (($#)); do
case "$1" in
-h|--help)
usage 0
;;
-a|--all)
all=1
;;
*)
usage 1 >&2
;;
esac
shift
done
if ! command -v apt-get >/dev/null; then if ! command -v apt-get >/dev/null; then
echo "pyenv: installing build prerequisites is not supported on this system" >&2 echo "pyenv: installing build prerequisites is not supported on this system" >&2
@ -33,6 +47,9 @@ prerequisites=(
libsqlite3-dev curl git llvm libncurses5-dev libncursesw5-dev xz-utils libsqlite3-dev curl git llvm libncurses5-dev libncursesw5-dev xz-utils
tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev libzstd-dev tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev libzstd-dev
) )
optional=(
libgdbm-dev
)
if [ "$(id -u)" -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then
apt_get=(apt-get) apt_get=(apt-get)
@ -44,4 +61,4 @@ else
fi fi
"${apt_get[@]}" update -q "${apt_get[@]}" update -q
"${apt_get[@]}" install -yq "${prerequisites[@]}" "${apt_get[@]}" install -yq "${prerequisites[@]}" ${all:+"${optional[@]}"}

View File

@ -4,18 +4,21 @@ load test_helper
_setup() { _setup() {
prerequisites="make build-essential libssl-dev zlib1g-dev libbz2-dev \ prerequisites="make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev curl git llvm libncurses5-dev \ libreadline-dev libsqlite3-dev curl git llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev \ libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev \
liblzma-dev libzstd-dev" liblzma-dev libzstd-dev"
optional="libgdbm-dev"
} }
@test "completion does not install packages" { @test "completions" {
stub apt-get stub apt-get
PATH="${BATS_TEST_DIRNAME}/../../../libexec:$PATH" \ run pyenv-install-prerequisites --complete
run pyenv completions install-prerequisites
assert_success "--help" assert_success <<!
--all
!
unstub apt-get unstub apt-get
} }
@ -28,7 +31,7 @@ liblzma-dev libzstd-dev"
unstub pyenv-help unstub pyenv-help
} }
@test "rejects arguments" { @test "invalid arguments" {
stub pyenv-help 'install-prerequisites : echo "Usage: pyenv install-prerequisites"' stub pyenv-help 'install-prerequisites : echo "Usage: pyenv install-prerequisites"'
run pyenv-install-prerequisites unexpected run pyenv-install-prerequisites unexpected
@ -50,6 +53,19 @@ liblzma-dev libzstd-dev"
unstub id unstub id
} }
@test "installs optional prerequisites with --all" {
stub id '-u : echo 0'
stub apt-get \
'update -q : true' \
"install -yq ${prerequisites} ${optional} : true"
run pyenv-install-prerequisites --all
assert_success
unstub apt-get
unstub id
}
@test "uses sudo when not running as root" { @test "uses sudo when not running as root" {
stub id '-u : echo 1000' stub id '-u : echo 1000'
stub apt-get stub apt-get