From da7a102f3cdb22313bd35a76ba8684858063af8b Mon Sep 17 00:00:00 2001 From: Yuri Victorovich Date: Thu, 14 Nov 2024 00:27:52 -0800 Subject: [PATCH] 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. --- Tools/scripts/pypi-get-latest-version.sh | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 Tools/scripts/pypi-get-latest-version.sh diff --git a/Tools/scripts/pypi-get-latest-version.sh b/Tools/scripts/pypi-get-latest-version.sh new file mode 100755 index 000000000000..2b7c71e56401 --- /dev/null +++ b/Tools/scripts/pypi-get-latest-version.sh @@ -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 " + 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'"