[Distutils] distlib - experience using the library

Vinay Sajip vinay_sajip at yahoo.co.uk
Mon Oct 29 16:11:55 CET 2012


Paul Moore <p.f.moore <at> gmail.com> writes:

> 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.

Thanks very much for the feedback.
 
> 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

Okay, I'll look at that.

> 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.

There are still plenty of rough edges in this area, but I hope to smooth them
out in due course.
 
> 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

It's probably the docs that need sorting out. With versions, distutils2 has
NormalizedVersion which conforms to PEP 386 (though there has been some
discussion here on changing the ordering of 'dev' w.r.t. other qualifiers).

However, any work with existing projects on PyPI means you have to consider
supporting other versions schemes, so I've added support for:

LegacyVersion - as per setuptools/distribute
SemanticVersion - as per semver.org
AdaptiveVersion - tries PEP-386, then the suggestion mechanism for PEP 386,
                  and then semantic

I'm not saying that all these version classes necessarily have to live on, but
it's useful to have them around at this stage in distlib's development, if
only for experimenting with.

Any of the above will give you an orderable version (you can only compare
instances of the same type, of course):

>>> from distlib.version import LegacyVersion as Version
>>> va, vb, vc, vd, vf, vp = [Version(s) for s in ('1.0-a1', '1.0-b2', '1.0rc3',
'1.0-dev', '1.0', '1.0p1')]
>>> va < vb
True
>>> va < vc
True
>>> va < vd
False
>>> va < vf
True
>>> va < vp
True
>>> vf < vp
True
>>> vc < vf
True
>>> 

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

Good to know. Thanks again for the feedback.

Regards,

Vinay Sajip



More information about the Distutils-SIG mailing list