Skip to content

Instantly share code, notes, and snippets.

@playpauseandstop
Last active August 29, 2015 14:04
Show Gist options
  • Save playpauseandstop/bb5c0fb0f8bbb271e61d to your computer and use it in GitHub Desktop.
Save playpauseandstop/bb5c0fb0f8bbb271e61d to your computer and use it in GitHub Desktop.
Check out available updates for virtual environment or system libraries with pip
#!/bin/bash
#
# Check out available updates for virtual environment or system libraries with
# `pip <http://pip.pypa.org/>`_.
#
# Requirements
# ============
#
# * GNU/Linux, Mac OS X
# * `pip`_ 1.4 or higher
#
# Installation
# ============
#
# Just put ``pip-list-updates`` somewhere to your ``$PATH`` (``~/bin`` is
# most obvious choice) and add exec guid to it with ``chmod +x``.
#
# Usage
# =====
#
# Checking available updates for virtual environment libraries::
#
# $ cd /path/to/project # If project contains venv dir(s)
# $ pip-list-updates
#
# ::
# $ workon <venv> # If virtualenvwrapper used
# (<venv>)$ pip-list-updates
#
# Checking available updates for system libraries::
#
# $ pip-list-updates # Make sure that `pwd` does not contain venv dir(s)
#
# Sort available updates by name::
#
# $ pip-list-updates -q | sort
#
found=0
quiet=$1
for dir in `pwd`/*; do
if [ -d "$dir" -a -f "$dir/bin/activate" ]; then
found=1
if [ "$quiet" != "-q" ]; then
echo "Available updates in '`basename $dir`' virtual environment:";
fi
"$dir/bin/pip" list -lo
fi
done
if [ $found -eq 0 ]; then
if [ "$quiet" != "-q" ]; then
if [ `python -c "import sys; print(1 if hasattr(sys, 'real_prefix') else 0);"` -eq 1 ]; then
echo "Available updates for '`basename $(python -c 'import sys; print(sys.prefix)')`' virtual environment:";
else
echo "Available updates for system libraries:";
fi
fi
pip list -lo
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment