Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PEP440 compliant AND git describe info available from deployed package

I would like to use use a Version Identification compliant with PEP440 but with a way to include the git information:

$ git describe --long
4.1-202-gab0f789

In PEP 440 there is a chapter about dvcs but this is not clear to me how the .devN suffix can hold a non numeric hash like the above: ab0f789. I need a way to request from one of my scripts on production the 4.1-202-gab0f789 info, so where in setup.py can I put the project metadata?

like image 836
user3313834 Avatar asked Feb 20 '16 10:02

user3313834


2 Answers

That section tells you not to use the hash:

As hashes cannot be ordered reliably such versions are not permitted in the public version field.

Emphasis mine.

They offer .devN as an alternative. If you are going to release developer versions from a git repository, number them, so .dev0, .dev1, etc. You could use tags to track these releases and track them back to specific revisions.

But if you read on, there is a way to tack on the hash as a local version number:

Identifying hash information may also be included in local version labels.

Add a +, then your hash (prefixed with g to ensure that an all-digit hash isn't compared as a number):

4.1.dev0+gab0f789

Local version numbers should only be used when creating a local non-indexed packaging or installation of your project however. Don't put a version with +<hash> on PyPI for example. But if you are producing packages from a continuous-integration server for developers to test, local version numbers are fine.

The setuptools-scm project uses that exact scheme to include the git hash in versions based on non-tag git commits.

like image 150
Martijn Pieters Avatar answered Sep 20 '22 19:09

Martijn Pieters


The problem with using the dev appendix for this is that for instance 4.1dev0+gab0f789 is semantically before the 4.1 release, while 4.1-202-gab0f789 from git describe actually mean that it is 202 commits behind 4.1.

like image 20
Florian Krause Avatar answered Sep 20 '22 19:09

Florian Krause