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

Version.serialize for SemVer fails after update to 1.6.0 #22

Closed
ghost opened this issue Aug 10, 2021 · 2 comments
Closed

Version.serialize for SemVer fails after update to 1.6.0 #22

ghost opened this issue Aug 10, 2021 · 2 comments
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Aug 10, 2021

Example:

from dunamai import Version
version = Version.from_git()
version_str = version.serialize(metadata=True, style=Style.SemVer)

Repository: https://github.com/splunk/addonfactory-ucc-generator

Traceback:

Traceback (most recent call last):
  File "/home/circleci/.venv/bin/ucc-gen", line 8, in <module>
    sys.exit(main())
  File "/home/circleci/.venv/lib/python3.7/site-packages/splunk_add_on_ucc_framework/__init__.py", line 873, in main
    _generate(args.source, args.config, args.ta_version)
  File "/home/circleci/.venv/lib/python3.7/site-packages/splunk_add_on_ucc_framework/__init__.py", line 691, in _generate
    version_str = version.serialize(metadata=True, style=Style.SemVer)
  File "/home/circleci/.venv/lib/python3.7/site-packages/dunamai/__init__.py", line 467, in serialize
    out = serialize_semver(base, pre=pre_parts, metadata=meta_parts)
  File "/home/circleci/.venv/lib/python3.7/site-packages/dunamai/__init__.py", line 1041, in serialize_semver
    check_version(serialized, Style.SemVer)
  File "/home/circleci/.venv/lib/python3.7/site-packages/dunamai/__init__.py", line 923, in check_version
    raise ValueError(failure_message)
ValueError: Version '0.3-beta.0.post.35+5a020de' does not conform to the Semantic Versioning style

dunamai 1.5.5 version:
Version(base='0.1.0', stage=None, revision=None, distance=224, commit='5a020de', dirty=True, tagged_metadata=None)

dunamai 1.6.0 version:
Version(base='0.3', stage='beta', revision=0, distance=35, commit='5a020de', dirty=True, tagged_metadata=None)

@mtkennerly
Copy link
Owner

mtkennerly commented Aug 10, 2021

Hi! This isn't an issue with Version.serialize, but rather is a side effect of a bug fix. Dunamai's default tag pattern previously required versions with three parts (v0.3.0), but that was an oversight, because Dunamai is meant to work also for other versioning systems like PEP 440 where 0.3 or 0.3.0.5 would be valid. So your v0.3 tag, which was previously ignored because it did not match the default pattern, is now being recognized as a version tag, so Dunamai tries to use it, but then it fails because it's invalid under Semantic Versioning (should be v0.3.0).

If you can't or don't want to change the tags, then you can pass a custom pattern to Version.from_git. This was the previous one, if you want to use it as-is:

_VERSION_PATTERN = r"""
(?x) (?# ignore whitespace)
^v(?P<base>\d+\.\d+\.\d+) (?# v1.2.3)
(-?((?P<stage>[a-zA-Z]+)\.?(?P<revision>\d+)?))? (?# b0)
(\+(?P<tagged_metadata>.+))?$ (?# +linux)
""".strip()

@ghost
Copy link
Author

ghost commented Aug 10, 2021

Hi! Thank you for the quick response. Yes, I investigated the issue a little bit more, you are correct. Thank you for the clarification.

@ghost ghost closed this as completed Aug 10, 2021
jonringer pushed a commit to jonringer/dunamai that referenced this issue Jan 14, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant