Execute some callback function to get current version#

For example, current repo state is:

commit 233f6d72 Dev branch commit (HEAD, dev)
|
|    commit 86269212 Release commit (v1.0.0, master)
|    |
|   commit e7bdbe51 Another commit
|    /
...
|
commit 273c47eb Long long ago
|
...

By default, when you try to get current version, you’ll receive some initial value (see starting_version option), because there are no tags in the dev branch.

If you want to get synchronized version numbers in both master and dev branches, you can create a function in some file (for example, in the my_module/version.py file):

def get_version():
    return "1.0.0"

Then place it in both the branches and update your config:

from my_module.version import get_version

setuptools.setup(
    ...,
    setup_requires=["setuptools-git-versioning>=2.0,<3"],
    setuptools_git_versioning={
        "enabled": True,
        "version_callback": get_version,  # <---
    },
)

When you’ll try to get current version in any branch, the result of executing this function will be returned instead of latest tag number.

If a value of this option is not a function but just str, it also could be used:

__version__ = "1.0.0"

Please take into account that any tag in the branch is completely ignored if version_callback is set. You should explicitly call setuptools_git_versioning.version_from_git function in the callback.

Note

Callback result is returned as is, so it should be a PEP 440 compatible version number

See also#