7

I want to use setuptools-scm to control my package version. My setup.py:

setuptools.setup(
...
    use_scm_version={'write_to': 'my-package/version.py'},
...
)

Currently I have v0.2 tag in my repo. I created new branch and added some commits. When I run python setup.py --version to create my-package/version.py file I get next tag v0.3 instead of current v0.2:

$ SETUPTOOLS_SCM_DEBUG=1 python3 setup.py --version
...
cmd 'git describe --dirty --tags --long --match *.*'
out b'v0.2-1-gb13420a\n'
cmd 'git rev-parse --abbrev-ref HEAD'
out b'feature-version-system\n'
tag v0.2
tag 'v0.2' parsed to {'version': 'v0.2', 'prefix': '', 'suffix': ''}
version pre parse v0.2
version <Version('0.2')>
version v0.2 -> 0.2
scm version <ScmVersion 0.2 d=1 n=gb13420a d=False b=feature-version-system>
config {'version_scheme': 'guess-next-dev', 'local_scheme': 'node-and-date'}
ep ('setuptools_scm.version_scheme', 'guess-next-dev')
ep found: guess-next-dev
ep ('setuptools_scm.local_scheme', 'node-and-date')
ep found: node-and-date
version 0.3.dev1
local_version +gb13420a
0.3.dev1+gb13420a  # <- I want to see 0.2.dev1+gb13420a here
$ git tag

v0.1
v0.2

I think it's wrong way, because my changes I'm working for are for current release tag v0.2, but setuptools_scm said that they belong v0.3. How to deal with it?

gerrit
  • 24,025
  • 17
  • 97
  • 170
approximatenumber
  • 467
  • 1
  • 7
  • 22

2 Answers2

10

For a while now setuptools-scm offers the option to use a post-release scheme, see setuptools_scm.version_scheme section. Then python setup.py --version and git describe --tag will give you the same information (different formatting though). To switch to a post-release scheme, include the following line in your setup.py:

setup(...
      use_scm_version={'version_scheme': 'post-release'},
      ...
      )
      
      
David
  • 1,909
  • 1
  • 20
  • 32
6

setuptools_scm is working correctly, because it's creating a pre-release of the next version. According to PEP440 section on pre-releases:

The pre-release segment consists of an alphabetical identifier for the pre-release phase, along with a non-negative integer value. Pre-releases for a given release are ordered first by phase (alpha, beta, release candidate) and then by the numerical component within that phase.

They also show the example as:

X.YaN   # Alpha release
X.YbN   # Beta release
X.YrcN  # Release Candidate
X.Y     # Final release

That means that 0.3.dev1+gb13420a is a pre-release version of 0.3, and comes after 0.2. 0.2.dev1+gb13420a would mean it's a pre-release of 0.2, and would be older than 0.2.

Jerr
  • 553
  • 1
  • 5
  • 15
  • 2
    Thanks for the answer. But I don't want to use pre-release strategy for my software, so I moved to simple custom script `bump-version.sh`, that does same things. It would be cool if `setup_scm` version strategy can be easily customized in future. – approximatenumber Jul 11 '19 at 08:26
  • @approximatenumber mind if you share what you have in `bump-version.sh`? – yuenherny Apr 12 '23 at 06:30
  • @yuenherny here you go: https://gist.github.com/approximatenumber/3e8dbddb8c261bb04b5d8e8d6ddba900 It's stupid, use it just as a reference. – approximatenumber Apr 13 '23 at 08:42