Skip to content

Instantly share code, notes, and snippets.

@jzempel
Last active December 11, 2015 15:59
Show Gist options
  • Save jzempel/4624227 to your computer and use it in GitHub Desktop.
Save jzempel/4624227 to your computer and use it in GitHub Desktop.
View a summary list of package release differences between your local environment and PyPI.
#!/usr/bin/env python
try:
from pip import get_installed_distributions
except ImportError:
from sys import exit
exit("pip not available")
from pkg_resources import parse_version
try:
from xmlrpclib import ServerProxy
except ImportError:
from xmlrpc.client import ServerProxy
pypi = ServerProxy("http://pypi.python.org/pypi")
for distribution in sorted(get_installed_distributions(),
key=lambda distribution: distribution.project_name):
remote = ''
project_name = distribution.project_name
releases = pypi.package_releases(project_name)
if not releases:
pypi.package_releases(project_name.capitalize())
if releases:
version = parse_version(releases[0])
if version > distribution.parsed_version:
remote = "PyPI:{0}=={1}".format(project_name, releases[0])
else:
remote = "PyPI:{0} not found".format(project_name)
local = "{0}=={1}".format(project_name, distribution.version)
print("{0:40} {1}".format(local, remote))
@jzempel
Copy link
Author

jzempel commented Dec 23, 2013

Updated for python3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment