Friday, February 19, 2016

Releasing Python Packages with PBR...

So it's been a while since I've had to release one of my Python-based projects and publish it to the PyPi distribution network. Publishing packages is generally really easy:


$ python setup.py sdist build
...
Writing myproj-x.y.z.tar.gz
...
$ twine upload -r pypi dist/myproj-x.y.z.tar.gz

However, I also use OpenStack's PBR (Python Build Reasonableness) as it makes the setup.py and related functionality very easy. However, it also complicates the above...

$ python setup.py sdist build
...
Writing myproj-x.y.z-devNNN.tar.gz
...
$

What to do?

If you look closely at the documentation for PBR you can find some notes for packagers - http://docs.openstack.org/developer/pbr/packagers.html. Among these notes is a statement about the environment variable PBR_VERSION - which is easy to overlook given the non-obvious link to the package your trying to release.

In the end, you just have to use PBR_VERSION to get it right and bypass any version calculations PBR itself does like so:

$ export PBR_VERSION=x.y.z
$ python setup.py sdist build
$ twine upload -r pypi dist/myproject-x.y.z.tar.gz

And voilĂ  it's the correct package for the version and now it's up on PyPi.