Script returns full binary name
This commit is contained in:
parent
f95979586d
commit
d44570b557
2 changed files with 25 additions and 25 deletions
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue