Similar questions like this were raised many times, but I was not able to find a solution for my specific problem.
I was playing around with setuptools_scm
recently and first thought it is exactly what I need. I have it configured like this:
pyproject.toml
[build-system]
requires = ["setuptools_scm"]
build-backend = "setuptools.build_meta"
[project]
...
dynamic = ["version"]
[tool.setuptools_scm]
write_to = "src/hello_python/_version.py"
version_scheme = "python-simplified-semver"
and my __init__.py
from ._version import __version__
from ._version import __version_tuple__
Relevant features it covers for me:
- I can use semantic versioning
- it is able to use *.*.*.devN version strings
- it increments minor version in case of
feature
-branches - it increments patch/micro version in case of
fix
-branches
This is all cool. As long as I am on my feature
-branch I am able to get the correct version strings.
What I like particularly is, that the dev version string contains the commit hash and is thus unique across multiple branches.
My workflow now looks like this:
- create
feature
orfix
branch - commit, (push, ) publish
- merge PR to
develop
-branch
As soon as I am on my feature
-branch I am able to run python -m build
which generated a new _version.py
with the correct version string accordingly to the latest git tag found. If I add new commits, it is fine, as the devN part of the version string changes due to the commit hash. I would even be able to run a python -m twine upload dist/*
now. My package is build with correct version, so I simply publish it. This works perfectly fine localy and on CI for both fix
and feature
branches alike.
The problem that I am facing now, is, that I need a slightly different behavior for my merged PullRequests
As soon as I merge, e.g. 0.0.1.dev####, I want to run my Jenkins job not on the feature
-branch anymore, but instead on develop
-branch. And the important part now is, I want to
- get
develop
-branch (done by CI) - update version string to same as on branch but without devN, so: 0.0.1
- build and publish
In fact, setuptools_scm is changing the version to 0.0.2.dev### now, and I would like to have 0.0.1.
I was tinkering a bit with creating git tags before running setuptools_scm
or build
, but I was not able to get the correct version string to put into the tag. At this point I am struggling now.
Is anyone aware of a solution to tackle my issue with having?:
- minor increment on
feature
-branches + add .devN - patch/micro increment on
fix
-branches + add .devN - no increment on
develop
-branch and version string only containing major.minor.patch of merged branch