Skip to content

Instantly share code, notes, and snippets.

@zoidyzoidzoid
Created July 4, 2017 17:37
Show Gist options
  • Save zoidyzoidzoid/8fbee6df24ecc846e0e1bb0e870d2239 to your computer and use it in GitHub Desktop.
Save zoidyzoidzoid/8fbee6df24ecc846e0e1bb0e870d2239 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Bash script for checking what installed packages in a virtualenv needs updates
#
# Requires:
# - OSX
# - core-utils installed (brew install core-utils)
# - pypi-cli installed (pip install pypi-cli)
#
# Example output:
# $ ./needs-updates.sh
# pytest needs to update. (currently: 2.8.7, latest: 3.1.3)
#
set -efuo pipefail
for requirement in $(pip freeze); do
package="$(echo "${requirement}" | awk -F"==" '{ print $1 }')"
current_version="$(echo "${requirement}" | gcut -d '=' -f 3-)"
# requests.get('https://pypi.python.org/pypi/pip/json').json()['info']['version']
latest_version="$(pypi info "${package}" | grep "Latest release" | gcut -d ":" -f 2- | tr -d "[:space:]")"
if [[ "${current_version}" != "${latest_version}" ]]; then
echo "${package} needs to update. (currently: ${current_version}, latest: ${latest_version})"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment