1

I feel lost. Each time I look at examples on how to write a Python package. I see a __version__ hardcoded in __init__.py. So we find the version hardcoded in:

  • setup.py
  • a Git tag
  • __version__
  • CHANGELOG

...

This doesn't look very SSOT at all.

Even today, it is a common way to write the version in setup.cfg. However, I would like only Git to hold the version, then use a git describe on the CI to populate whatever needs to be populated.

Is there any proper way to let my CI do the job for me?

Why most popular packages have hardcoded versions?

nowox
  • 25,978
  • 39
  • 143
  • 293
  • This may help [rewrite python version with git](https://stackoverflow.com/questions/5581722/how-can-i-rewrite-python-version-with-git) [python package versionig](https://martin-thoma.com/python-package-versions/) – sahasrara62 Oct 30 '20 at 08:17
  • @sahasrara62 I saw this, but this doesn't help to really be SSOT – nowox Oct 30 '20 at 08:18
  • Most packages keep version in init.py, simply because the version is part of the package. With version kept somewhere else you need a build process and thus this "something else" (e.g. git) has to be a part of the package. Why limit yourself so much? – freakish Oct 30 '20 at 08:21
  • @freakish Why is it better to have a redundancy of information? – nowox Oct 30 '20 at 08:21
  • @nowox what do you mean by "redundancy"? Git commit versions serve different purpose. – freakish Oct 30 '20 at 08:21
  • @freakish I limit myself so much because I believe in a single source of truth. – nowox Oct 30 '20 at 08:22
  • @nowox I still don't understand. Why init.py can't be the SSOT? – freakish Oct 30 '20 at 08:23
  • @freakish With `git tag` you can sign a commit with a tag that sets the version of your package. This is the role of your source content version manager. Then inside the repository, you should have the code, only the code not such metadata. – nowox Oct 30 '20 at 08:24
  • @nowox that becomes problematic once you move the code to some other repository. Or even without repository at all, by whatever means. With your approach you strongly couple your project with git. Which I believe should be avoided. And I strongly believe that every information relevant to the project should be kept in the project itself. – freakish Oct 30 '20 at 08:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/223857/discussion-between-nowox-and-freakish). – nowox Oct 30 '20 at 08:27
  • https://stackoverflow.com/search?q=%5Bsetuptools%5D+bump+version – phd Oct 30 '20 at 10:47

0 Answers0