Jens W. Klein wrote:
Am Wed, 24 Jun 2009 09:59:14 -0400 schrieb Tres Seaver:
Missing is a version fixation like done in ZTK, Grok, Plone, ... I'd
really like to see such a version.cfg for each repoze release. Creation
could be automated.
You shouldn't need to pin the versions if you would use the index as an

   index =

That index is a "known good set" for the 1.0 release line of BFG.

If one uses only stuff from the given index it works. Now, using stuff from pypi like repoze.what make live difficult using an own index server.

I agree it's useful to have a versions.cfg, so I wrote a WSGI script that generates a versions.cfg from a package index. I have attached it. It probably needs some battle testing and TLC.


URI = ''

import lxml.html
import os
import pkg_resources
import urlparse

def application(environ, start_response):
    packages = get_index_versions(URI)
    lines = ['[versions]']
    for pkg_name, version in sorted(packages.items()):
        lines.append('%s = %s' % (pkg_name, version))
    text = '\n'.join(lines)
        ('Content-Type', 'text/plain'),
        ('Content-Length', str(len(text))),
    return [text]

def get_index_versions(uri):
    packages = {}  # pkg_name -> [(parsed version, version)]
    doc = lxml.html.parse(uri)
    for e in doc.findall('//a'):
        href = e.get('href')
        if not href:
        path = urlparse.urlsplit(href)[2]
        parts = filter(None, path.split('/'))
        if not parts:
        basename, ext = os.path.splitext(parts[-1])
        ext = ext.lower()
        if ext == '.egg':
            # remove the '-pyX.Y-Z' suffixes
            basename = '-'.join(basename.split('-')[:-2])
        elif ext in ('.gz', '.bz2'):
            basename, ext = os.path.splitext(basename)
            ext = ext.lower()
        if ext not in ('.tar', '.zip', '.egg', '.tgz', '.tbz2'):
        pkg_name, version = basename.split('-', 1)
        parsed_version = pkg_resources.parse_version(version)
        versions = packages.setdefault(pkg_name, [])
        versions.append((parsed_version, version))
    res = {}
    for pkg_name, versions in packages.items():
        res[pkg_name] = versions[-1][1]
    return res

if __name__ == '__main__':
    print ''.join(application({}, lambda headers: None))
Repoze-dev mailing list

Reply via email to