Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_version(version_scheme='python-simplfied-semver') fails when considering a semantic version tag with pre-release or build IDs #479

Closed
jasongraham opened this issue Sep 21, 2020 · 1 comment

Comments

@jasongraham
Copy link

Steps to reproduce:

  • setuptools-scm-4.1.2
  • Python 3.8
  • Create git repository with arbitrary contents.
  • Tag your most recent commit with a release that specifies a semantic version and includes a pre-release or build identifier. I used 1.0.0-foo
>>> import setuptools_scm as scm
>>> scm.get_version(version_scheme='python-simplified-semver')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../site-packages/setuptools_scm/__init__.py", line 144, in get_version
    return _get_version(config)
  File .../site-packages/setuptools_scm/__init__.py", line 151, in _get_version
    version_string = format_version(
  File ".../site-packages/setuptools_scm/version.py", line 345, in format_version
    main_version = version_scheme(version)
  File ".../site-packages/setuptools_scm/version.py", line 258, in simplified_semver_version
    return guess_next_simple_semver(version.tag, retain=SEMVER_LEN, increment=False)
  File ".../site-packages/setuptools_scm/version.py", line 246, in guess_next_simple_semver
    parts = [int(i) for i in str(version).split(".")[:retain]]
  File ".../site-packages/setuptools_scm/version.py", line 246, in <listcomp>
    parts = [int(i) for i in str(version).split(".")[:retain]]
ValueError: invalid literal for int() with base 10: '0-foo'

I had expected in this case that the tag name would be used as the version (1.0.0-foo).

A similar exception gets raised looking back toward that tag in a later added commit.

...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../site-packages/setuptools_scm/__init__.py", line 144, in get_version
    return _get_version(config)
  File ".../site-packages/setuptools_scm/__init__.py", line 151, in _get_version
    version_string = format_version(
  File ".../site-packages/setuptools_scm/version.py", line 345, in format_version
    main_version = version_scheme(version)
  File ".../site-packages/setuptools_scm/version.py", line 265, in simplified_semver_version
    return version.format_next_version(
  File ".../site-packages/setuptools_scm/version.py", line 179, in format_next_version
    guessed = guess_next(self.tag, **kw)
  File ".../site-packages/setuptools_scm/version.py", line 246, in guess_next_simple_semver
    parts = [int(i) for i in str(version).split(".")[:retain]]
  File ".../site-packages/setuptools_scm/version.py", line 246, in <listcomp>
    parts = [int(i) for i in str(version).split(".")[:retain]]
ValueError: invalid literal for int() with base 10: '0-foo'

In this case, I would expect that the created version would either something like 1.0.0-devN... or more ideally 1.0.0-foo.devN.

Looking at the code listed in the traceback, it looks like the tool would also choke on any build IDs that were included, though I expect creating a tag with that information would be weird.

I do think that tags with pre-release IDs on them are common enough that I would expect these to work.

@RonnyPfannschmidt
Copy link
Contributor

In that case we should throw a better error, the simplified semver only handles numbers

Python versions don't directly support semver data, one is supposed to add that kinda data in local tags (where setuptools _scm could have some better tooling)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment