Avoid having version number in source code

I like to release often. The downside: Many changes in the git repo are changes
to the version number.

How could I avoid this?

I don’t need Semantic Versioning in this case.

Something like YYYY.MM.DD-NNN would be enough.

Do you have an idea how this could be done?

I don’t understand the question. If you’re using setuptools, you can calculate the version number at build time in setup.py. What else do you need?

1 Like

IIUC, you don’t want to keep version number in source code. Then you can retrieve it from SCM(e.g. git tag). setuptools-scm enables it for setuptools

PDM also has native support for this, simply specify version as version = {use_scm = true}

5 Likes

A similar solution is provided by pbr · PyPI
(which also allows you to avoid keeping things like changelogs and
author lists in your source tree). Like SetupTools-SCM, PBR
calculates version numbers from tags, and can predict upcoming
version bumps from structured footers in commit messages in order to
more accurately form dev versions.

1 Like

#SelfPromotion :slight_smile:

This package pip install tag2ver will update all your version numbers, tag, upload to remote (optional), and upload to PyPI (optional) in one hit. So it might take the pain of doing frequent releases away. It does for me - that’s why I wrote it!

Since you seem to want to do something similar to CalVer, I’ll shamelessly self promote as well: calver · PyPI will let you generate a version based on the current date.

2 Likes

@pf_moore thank you for this hint.

I was thinking the old fashioned input-processing-output way.

I dreamed that there is way to pass the version number via an argument on the command line.

Up to now I only use a setup.cfg, and don’t need a setup.py.

But you are right. I could get the version number from somewhere in setup.py and then pass the version number to setup().

[…]

I could get the version number from somewhere in setup.py and then
pass the version number to setup().

This is pretty much exactly how libs like PBR and Setuptools-SCM
inject versions extracted from Git tags.

I published my solution here: setuptools - python3 -m build ... supply version number via command line argument - Stack Overflow

1 Like

Yep, that looks very similar to PBR’s environment variable solution
with PBR_VERSION completely overriding its usual version
autodetection logic (but much simpler of course because you don’t
have a separate and basically unnecessary setup_requires to deal
with):

https://docs.openstack.org/pbr/latest/user/packagers.html#versioning

I looked in the SetupTools-SCM docs and couldn’t find a similar
option for it though.

SETUPTOOLS_SCM_PRETEND_VERSION?

Aha, yep thanks! I was apparently staring right at it in the
environment variables section of the readme and didn’t see it.

So anyway, both PBR and SetupTools-SCM have options to override
version numbers from an envvar instead of taking them from revision
control tags, but of course as shown it’s trivial to roll your own
version override from an envvar in a setup.py file too.

I created a issue at github: https://github.com/pypa/build/issues/347

Let’s wait and see if other people have the same issue.