distutils.version / test_pypi_versions.py

#
## test_pypi_versions.py
##
##  A very simple test to see what percentage of the current pypi packages
##  have versions that can be converted automatically by distutils' new
##  suggest_rational_version() into PEP-386 compatible versions.
##
##  Requires : Python 2.5+
#

try:
   import cPickle as pickle
except:
   import pickle

import xmlrpclib
import os.path

from verlib import suggest_rational_version

INDEX_PICKLE_FILE = 'pypi-index.pkl'
VERSION_PICKLE_FILE = 'pypi-version.pkl'

package_info = version_info = []

#
## Get pypi full package list if the file's not found, else restore it
#
if not os.path.exists(INDEX_PICKLE_FILE):
    print "Retrieving pypi packages..."
    server = xmlrpclib.Server('http://pypi.python.org/pypi')
    package_info  = server.search({'name': ''})

    print "Saving package info.."
    with open(INDEX_PICKLE_FILE, 'wb') as o:
        pickle.dump(package_info, o)
else:
    print "Loading saved pypi data..."
    with open(INDEX_PICKLE_FILE, 'rb') as f:
        package_info = pickle.load(f)

#
## Save pypi package's version info  Get pypi full package list if the file's
## not found, else restore it
#
versions = []
if not os.path.exists(VERSION_PICKLE_FILE):
    print "Number of Packages = ", len(package_info)
    versions = [p['version'] for p in package_info]
    with open(VERSION_PICKLE_FILE, 'wb') as o:
        pickle.dump(versions, o)
else:
    with open(VERSION_PICKLE_FILE, 'rb') as f:
        versions = pickle.load(f)

total_versions = len(versions)
matches = 0.00
no_sugg = 0.00
have_sugg = 0.00

for ver in versions:
    sugg = suggest_rational_version(ver)
    if sugg == ver:
        matches += 1
    elif sugg == None:
        no_sugg += 1
    else:
        have_sugg += 1

pct = "(%2.2f%%)"
print "Results:"
print "--------"
print "Total Packages  : ", total_versions
print "Already Match   : ", matches, pct % (matches/total_versions*100,)
print "Have Suggestion : ", have_sugg, pct % (have_sugg/total_versions*100,)
print "No Suggestion   : ", no_sugg, pct % (no_sugg/total_versions*100,)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.