Script returns full binary name

This commit is contained in:
cyqsimon 2023-03-14 16:56:20 +08:00
parent f95979586d
commit d44570b557
No known key found for this signature in database
GPG key ID: 1D8CE2F297390D65
2 changed files with 25 additions and 25 deletions

View file

@ -96,28 +96,16 @@ build-deps-ubuntu:
docs: docs-deps docs-build
docs-build: .PHONY
@if ! SUFFIX=$$(tools/get-best-python-for-docs-build.sh); then \
echo "ERROR: could not find a recent version of Python. mkdocs needs >= 3.8"; \
exit 1; \
fi; \
echo "python$$SUFFIX $$(which mkdocs) build"; \
"python$$SUFFIX" $$(which mkdocs) build
PY=$$(tools/get-python-bin.sh python) && MKDOCS=$$(which mkdocs) && \
$$PY $$MKDOCS build
docs-deps: .PHONY
@if ! SUFFIX=$$(tools/get-best-python-for-docs-build.sh); then \
echo "ERROR: could not find a recent version of Python. mkdocs needs >= 3.8"; \
exit 1; \
fi; \
echo "pip$$SUFFIX install -r requirements.txt"; \
"pip$$SUFFIX" install -r requirements.txt
PIP=$$(tools/get-python-bin.sh pip) && \
$$PIP install -r requirements.txt
docs-deps-update: .PHONY
@if ! SUFFIX=$$(tools/get-best-python-for-docs-build.sh); then \
echo "ERROR: could not find a recent version of Python. mkdocs needs >= 3.8"; \
exit 1; \
fi; \
echo "pip$$SUFFIX install -r requirements.txt --upgrade"; \
"pip$$SUFFIX" install -r requirements.txt --upgrade
PIP=$$(tools/get-python-bin.sh pip) && \
$$PIP install -r requirements.txt --upgrade
# Web app

View file

@ -1,20 +1,31 @@
#!/usr/bin/env bash
# This script prints the version suffix of the most suitable version of Python
# for building docs that's installed in this system.
# Synopsis:
# - get-python-bin.sh python
# - get-python-bin.sh pip
#
# Caller can safely append this suffix to `python` or `pip` and expect the
# binary to exist.
# This script selects the most suitable `python` / `pip` binary available
# for building docs that's installed in this system.
#
# If no usable version of Python is available, this script will exit with a
# non-zero code.
set -e
case "$1" in
"python" | "pip")
BIN_PREFIX="$1"
;;
*)
echo "Incorrect usage" >&2
exit 1
;;
esac
# if `python3` is >= 3.8 and `pip3` is available, use that
if echo -e "import sys\nif sys.version_info < (3,8):\n exit(1)" | python3 && \
which pip3 1>/dev/null 2>&1; then
echo "3"
echo "${BIN_PREFIX}3"
exit 0
fi
@ -24,10 +35,11 @@ for SUFFIX in ${CANDIDATE_SUFFIXES[@]}; do
# if both `python3.N` and `pip3.N` are available, use that
if which "python$SUFFIX" 1>/dev/null 2>&1 && \
which "pip$SUFFIX" 1>/dev/null 2>&1; then
echo "$SUFFIX"
echo "${BIN_PREFIX}${SUFFIX}"
exit 0
fi
done
# none found
exit 1
echo "No suitable version of Python found" >&2
exit 2