[Distutils] distlib - experience using the library

Paul Moore p.f.moore at gmail.com
Mon Oct 29 15:39:39 CET 2012


In order to get a feel for distlib, I spent a short time today writing
a quick script to solve a problem I currently have. The results will
hopefully be of some use in pointing out some "real world" experience
with the library.

The problem is as follows: I maintain a small library of sdists
downloaded from PyPI, for offline use and to speed things up when I'm
building virtualenvs. A maintenance issue with this approach is
keeping the library reasonably up to date. It's not a huge issue, so
I've never invested much time in writing anything to solve it, but it
seemed a reasonable task for distlib.

First of all, the positives:
1. It really was "a short time" I spent. Less time than it took me to
write this mail. The locator API is beautifully easy to use, and fits
this use case perfectly.
2. Although the resulting code is a quick hack, it's clean and readable.
3. Extending the code looks very straightforward. I haven't tried yet,
but adding extra indexes, adding a download capability, all look
simple.

Areas where I found things lacking:

I'd really like to have a means of getting all distributions from a
locator. Something like the
distlib.locators.get_all_distribution_names function, but on a
locator. It would only be available on certain locators (specifically,
the XMLRPC and directory ones) but for my script, it would have saved
writing a directory scanning function and duplicating the filename
parsing from the locator library.

The dance to create a Distribution object from some data
        md = Metadata()
        md['Name'] = p
        md['Version'] = v
        dist = Distribution(md)
cries out for a convenience method. On the other hand, I'm not sure
how much advantage there is in using Distribution objects over just
passing round the raw name and version strings for code as simple as
mine.

The version API seems very complex. I was expecting to just do
something like Version(string) to get a sortable version object. Given
that some of my packages use deliberately non-standard custom versions
(2.3.x20121023) that's probably insufficient, but for this application
I'm not really interested in validating versions. Using
distutils.version.LooseVersion actually works better for me because it
"just works". Is there some way to get the forgiving convenience of

    if distutils.version.LooseVersion(v1) > distutils.version.LooseVersion(v2):
        # whatever

with distlib?

But regardless, these are minor quibbles. The overall experience was
very positive.

Paul.


More information about the Distutils-SIG mailing list