Version handling¶
Where does the version come from?¶
A version number is essentially what zest.releaser cannot do without. A version number can come from various different locations:
The
setup.pyfile. Two styles are supported:version = '1.0' def setup( version=version, name='...
and also:
def setup( version='1.0', name='...
The
pyproject.tomlfile. zest.releaser will look for something like:[project] name = "..." version = "1.0"
The
setup.cfgfile. zest.releaser will look for something like:[metadata] name = ... version = 1.0
If no
setup.pyis found, zest.releaser looks for aversion.txtfile. It should contain just a version number (a newline at the end is OK).Originally the
version.txtwas only meant to support really old and ancient Plone packages, but it turned out to be quite useful for non-Python packages, too. A completely static website, for instance, that you do want to release and that you do want a changelog for.A
__version__attribute in a Python file. You need to tell zest.releaser which Python file by adding (or updating) thesetup.cfgfile next to thesetup.py. You need a[zest.releaser]header and apython-file-with-versionoption:[zest.releaser] python-file-with-version = mypackage/__init__.py
Alternatively, in
pyproject.toml, you can use the following:[tool.zest-releaser] python-file-with-version = "mypackage/__init__.py"
Because you need to configure this explicitly, this option takes precedence over any
setup.py,setup.cfgorpyproject.tomlpackage version, orversion.txtfile.
Where is the version number being set?¶
Of those four locations where the version can come from, only the first one found is also set to the new value again. Zest.releaser assumes that there’s only one location.
According to PEP 396, the version should have one source and all the others should be derived from it.
Using the version number in setup.py or setup.cfg as __version__¶
Here are opinionated suggestions from the zest.releaser main authors about how to use the version information. For some other ideas, see the zest.releaser issue 37 discussion.
The version in the
setup.pyis the real version.Add a
__version__attribute in your main module. Often this will be an__init__.py. Set this version attribute withimportlib.metadata. Here’s the code fromzest/releaser/__init__.py:from importlib.metadata import version __version__ = version("zest.releaser")
This way you can do:
>>> import zest.releaser >>> zest.releaser.__version__ '3.44'
If you use Sphinx for generating your documentation, use the same
importlib.metadatatrick to set the version and release in your Sphinx’sconf.py. See zest.releaser’s conf.py.