pimoroni / boilerplate-python

Boilerplate and common files/structure for a Pimoroni Python library.
MIT License
1 stars 1 forks source link

Use pkg_resources.parse_version directly. #2

Closed jezdez closed 5 years ago

jezdez commented 5 years ago

This should reduce the risk for breakage when setuptools stops using pkg_resources itself in the setuptools.version module.

The gist is that lots of pkg_resources functionality is being added to Python (3.7 and 3.8) in importlib (and backported in https://pypi.org/project/importlib-metadata/ and https://pypi.org/project/importlib_resources/). I don't know all the details but I would be seriously surprised if pkg_resources' days wouldn't be counted.

In theory there is already a better implementation for the version comparison that pkg_resources and setuptools already use internally, which is the packaging library, that both vendor under setuptools.extern.packaging and pkg_resources.extern.packaging.

The import looks like this instead:

from setuptools.extern.packaging import version

assert version.parse('40') < version.parse('41')

Looking back, the "packaging" library was vendored in setuptools 8.0 in December 2014 (!) and is used as the default version comparison method since then. IIRC only Debian Jessie ships with an older setuptools version. Stretch and Buster have it.

Gadgetoid commented 5 years ago

Wow! Thank you. A great deal of the time I'm building out this boilerplate in a black-box, so I'm really keen to have additional input on it.

I've tried from setuptools.extern.packaging import version across a number of historic setuptools packages to no avail- I'm guessing (and from peering in the source confirming some of my suspicions) that the mechanism for vendoring these packages is more complicated than I'd assumed. I'm keen to run with the most current method of version comparison that I can, however, to mitigate having to make sweeping changes across multiple libraries in future.

Looks like Jessie ships with ~5.5.1 and I'm not quite sure what our policy will be regarding supporting it. Right now I still run it on a few systems myself!