Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consistent versioning in Python project

I have a Python project which has Sphinx documentation and distutils for publishing to Pip.

Both of these functions require a version (e.g., 0.4b3)

Is there a best practice for automatically maintaining a consistent version number across the various utilities which require version numbers?

As a bonus, is there anything that integrates with git (e.g., via tags)?

like image 769
muckabout Avatar asked Feb 16 '12 13:02

muckabout


People also ask

Does Python follow semantic versioning?

The unique identifier you use may be name-based or number-based, but most Python packages use semantic versioning. In semantic versioning, a version number consists of three integers A.B.C, where A is the “major” version, B is the “minor” version, and C is the “patch” version.

What is __ version __ in Python?

The special variable __version__ is a convention in Python for adding version numbers to your package. It was introduced in PEP 396. We'll talk more about versioning later. Variables defined in __init__.py become available as variables in the package namespace: >>> >>> import reader >>> reader.


1 Answers

This is a favorite question on Python distutils mailing lists. You can import your module from setup.py as well as from conf.py and get module.version. This may not work depending on your imports, your use of 2to3 or other factors, in which case you can move your version to a text file and open that from your module, setup.py and conf.py.

My personal take on this is that it’s no great burden to update the version number in three places. It’s a minor step in the release process.

like image 115
merwok Avatar answered Sep 19 '22 06:09

merwok