mirror of
https://github.com/apisnetworks/pyenv.git
synced 2026-11-30 19:59:01 +00:00
python-build: show download progress in interactive terminals
--- Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
67dbc6e930
commit
8339b9b033
4 files changed
+170
-5
No files matched your search
@@ -8,6 +8,21 @@ _setup() {
|
||||
mkdir -p "${PYTHON_BUILD_BUILD_PATH}"
|
||||
}
|
||||
|
||||
check_script_available() {
|
||||
command -v script >/dev/null || skip "'script' not installed"
|
||||
}
|
||||
|
||||
run_with_script() {
|
||||
local command
|
||||
# `script' outputs CRLF because ttys do so under the hood
|
||||
# https://unix.stackexchange.com/questions/343324/why-in-the-output-of-script-1-the-newline-is-cr-lf-dos-style
|
||||
case "$(uname -s)" in
|
||||
Linux) printf -v command '%q ' "$@"; script -qec "$command" /dev/stdout | tr -d $'\r' ;;
|
||||
*) script -q /dev/stdout "$@" | tr -d $'\r' ;;
|
||||
esac </dev/null
|
||||
return ${PIPESTATUS[0]}
|
||||
}
|
||||
|
||||
@test "failed download displays error message" {
|
||||
stub curl false
|
||||
|
||||
@@ -17,6 +32,22 @@ _setup() {
|
||||
assert_output_contains "error: failed to download package-1.0.0.tar.gz"
|
||||
}
|
||||
|
||||
@test "interactive download progress is both shown and logged" {
|
||||
check_script_available
|
||||
export TMPDIR="$BATS_TEST_TMPDIR"
|
||||
stub curl '** -o * ** --no-silent ** http://example.com/* : "'"$BASH"'" -ec '\''echo download-progress >&2; "$FIXTURE_ROOT/fake_downloader" "$@"'\'' "$@"'
|
||||
|
||||
run run_with_script python-build "$FIXTURE_ROOT/definitions/without-checksum" "$INSTALL_ROOT"
|
||||
assert_success
|
||||
unstub curl
|
||||
|
||||
assert_line download-progress
|
||||
|
||||
run cat "$BATS_TEST_TMPDIR"/python-build.*.log
|
||||
assert_success
|
||||
assert_line download-progress
|
||||
}
|
||||
|
||||
@test "using aria2c if available" {
|
||||
export PYTHON_BUILD_ARIA2_OPTS=
|
||||
export -n PYTHON_BUILD_HTTP_CLIENT
|
||||
@@ -33,6 +64,23 @@ OUT
|
||||
unstub aria2c
|
||||
}
|
||||
|
||||
@test "interactive aria2c output is emulated by printing summaries" {
|
||||
check_script_available
|
||||
export TMPDIR="$BATS_TEST_TMPDIR"
|
||||
export PYTHON_BUILD_ARIA2_OPTS=
|
||||
export -n PYTHON_BUILD_HTTP_CLIENT
|
||||
stub aria2c '** --summary-interval=* ** http://example.com/* : "'"$BASH"'" -ec '\''echo download-progress; "$FIXTURE_ROOT/fake_downloader" aria2c "$@"'\'' "$@"'
|
||||
|
||||
run run_with_script python-build "$FIXTURE_ROOT/definitions/without-checksum" "$INSTALL_ROOT"
|
||||
assert_success
|
||||
unstub aria2c
|
||||
assert_line download-progress
|
||||
|
||||
run cat "$BATS_TEST_TMPDIR"/python-build.*.log
|
||||
assert_success
|
||||
assert_line download-progress
|
||||
}
|
||||
|
||||
@test "fetching from git repository" {
|
||||
stub git "clone --depth 1 --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"
|
||||
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
aria2c=
|
||||
wget=
|
||||
src=
|
||||
dest=
|
||||
dir_=
|
||||
|
||||
case "$1" in
|
||||
aria2c)
|
||||
aria2c=1;;
|
||||
wget)
|
||||
wget=1;;
|
||||
esac
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
-o)
|
||||
if [[ -z $wget ]]; then
|
||||
dest="$2"
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
-O)
|
||||
if [[ -n $wget ]]; then
|
||||
dest="$2"
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
-d)
|
||||
if [[ -n $aria2c ]]; then
|
||||
dir_="$2/"
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
-*)
|
||||
;;
|
||||
*)
|
||||
src="$FIXTURE_ROOT/${1##*/}"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
cp "$src" "${dir_}${dest}"
|
||||
|
||||
@@ -138,6 +138,19 @@ assert_output_contains() {
|
||||
}
|
||||
}
|
||||
|
||||
assert_line() {
|
||||
if [ "$1" -ge 0 ] 2>/dev/null; then
|
||||
assert_equal "$2" "${lines[$1]}"
|
||||
else
|
||||
local line
|
||||
for line in "${lines[@]}"; do
|
||||
if [ "$line" = "$1" ]; then return 0; fi
|
||||
done
|
||||
flunk "expected line \`$1'" $'\n'\
|
||||
"output: $output"
|
||||
fi
|
||||
}
|
||||
|
||||
# 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() {
|
||||
|
||||
Reference in new issue
Block a user