1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-18 00:10:04 +00:00

Tools/scripts: add pypi-get-latest-version.sh

pypi-get-latest-version.sh retrieves the latest version of any
Python package as registered on https://pypi.org

It makes it easy to check the latest version from the command line.
This commit is contained in:
Yuri Victorovich 2024-11-14 00:27:52 -08:00
parent 424d6490ef
commit da7a102f3c

View File

@ -0,0 +1,45 @@
#!/bin/sh
#
# MAINTAINER: yuri@FreeBSD.org
set -e
set -o pipefail
export LC_ALL=C
##
## pypi-get-latest-version.sh: retrieves the latest version of a given Python package as registered on https://pypi.org
##
# args
PACKAGE_NAME="$1"
if [ -z "$PACKAGE_NAME" ]; then
echo "Usage: $0 <package-name>"
exit 1
fi
# check that packaged dependencies are installed
for dep in jq version_sort; do
if ! which -s $dep; then
echo "error: the '$dep' dependency is missing"
if [ $dep == "jq" ]; then
echo "... please install the 'jq' package"
elif [ $dep == "version_sort" ]; then
echo "... please install the 'libversion' package"
fi
exit 1
fi
done
# MAIN
fetch -o - https://pypi.python.org/pypi/$PACKAGE_NAME/json 2>/dev/null |
jq -r '.releases | keys[]' |
grep -v dev |
version_sort |
tail -1 ||
echo "failed to find the Python package '$PACKAGE_NAME'"