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)?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With