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

Always assumes repo is tagged using SemVer #21

Closed
yajo opened this issue Jul 18, 2021 · 3 comments
Closed

Always assumes repo is tagged using SemVer #21

yajo opened this issue Jul 18, 2021 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@yajo
Copy link

yajo commented Jul 18, 2021

See this session:

❯ git init .

❯ touch a

❯ git add -A

❯ git commit -amwip
[master (commit-raíz) dfbff1f] wip
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a

❯ git tag v1

❯ dunamai from git --style pep440
Pattern '(?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)' did not match any tags from ['v1']

It seems that even when I add --style pep440 to the command, dunamai only tries to find tags formatted with semver, because it's using this regexp:

_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()

With that regexp for example, these tags would fail:

  • 1
  • v1
  • v1.0
  • 1.2.3
  • 0.1.0.1
  • 1.2.3.alpha1.post4.dev3

So I think that it should:

  1. prefix v be optional
  2. add a specific regex for each versioning system

As a workaround, there's the possibility to pass a custom pattern if running from python:

dunamai/dunamai/__init__.py

Lines 851 to 857 in 14a9891

:param pattern: Regular expression matched against the version source.
This must contain one capture group named `base` corresponding to
the release segment of the source. Optionally, it may contain another
two groups named `stage` and `revision` corresponding to a prerelease
type (such as 'alpha' or 'rc') and number (such as in 'alpha-2' or 'rc3').
It may also contain a group named `tagged_metadata` corresponding to extra
metadata after the main part of the version (typically after a plus sign).

@yajo
Copy link
Author

yajo commented Jul 18, 2021

I found this, that should help to know what makes a string parseable into pep440: https://github.com/pypa/packaging/blob/d59efa2141210447ae21c4d48813d720e0d1dbfd/packaging/version.py#L225-L254

@mtkennerly mtkennerly added the bug Something isn't working label Aug 9, 2021
@mtkennerly mtkennerly added this to the v1.6.0 milestone Aug 9, 2021
@mtkennerly
Copy link
Owner

Hi! Sorry for the late response, and thanks for pointing this out. I'll definitely relax ^v(?P<base>\d+\.\d+\.\d+) to ^v(?P<base>\d+(\.\d+)*), since that was an oversight. The v prefix was a conscious decision, though, to avoid false positives from things like ticket ID-based tags, so I would consider that a backwards-incompatible change. I think the pattern should be general enough so that it doesn't need different defaults for different versioning systems, but I would be open to adding extra defaults if there's a clear need.

As a workaround, there's the possibility to pass a custom pattern if running from python:

For reference, this is also available from the command line as --pattern.

@mtkennerly
Copy link
Owner

This is now fixed in 1.6.0.

jonringer pushed a commit to jonringer/dunamai that referenced this issue Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants