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

dunamai.Version.from_git() fails if 'v' prefix not set #61

Closed
cclecle opened this issue Mar 15, 2023 · 4 comments
Closed

dunamai.Version.from_git() fails if 'v' prefix not set #61

cclecle opened this issue Mar 15, 2023 · 4 comments
Labels
question Further information is requested

Comments

@cclecle
Copy link

cclecle commented Mar 15, 2023

If I have a repository with a version tagged 0.1.3.post1 (exemple), doing a dunamai.Version.from_git() will fail because of the missing front 'v'.
I managed to make it work in my project by doing a preliminary step:

dunamai.VERSION_SOURCE_PATTERN = r"""
    (?x)                                                        (?# ignore whitespace)
    ^v?((?P<epoch>\d+)!)?(?P<base>\d+(\.\d+)*)                  (?# v1.2.3 or v1!2000.1.2)
    ([-._]?((?P<stage>[a-zA-Z]+)[-._]?(?P<revision>\d+)?))?     (?# b0)
    (\+(?P<tagged_metadata>.+))?$                               (?# +linux)
""".strip()

Notice the '?' after the v.

Isn't a thing it should support from scratch as PEP440 does not require it ?

Note: using version 1.15.0

@mtkennerly
Copy link
Owner

This is intentional as the default behavior, but you can set --pattern default-unprefixed (or in Python: pattern=Pattern.DefaultUnprefixed) to make the v optional. You can also pass in custom patterns without having to patch the library's constant.

This is covered in the README: https://github.com/mtkennerly/dunamai#tips

Isn't a thing it should support from scratch as PEP440 does not require it ?

The main reason is to prevent false positives from tags that weren't meant to be a version. For example, without the v, it would turn tags like 3.11-compat into version 3.11compat0.

@mtkennerly mtkennerly added the question Further information is requested label Mar 16, 2023
@cclecle
Copy link
Author

cclecle commented Mar 16, 2023

Ok thanks, but is avoiding user errors really more important than being compliant with standards... ?

  • Both PEP440 ans SemVer doesn't have this prefix.
  • if one is using dunamai, he would certainly use version identifier only as tag..

Would make more sense to have an option to disable it.

But anyway, the problem is not on my own code but through copier .
I will raise an issue on there side to see if they can add the corresponding option..

@mtkennerly
Copy link
Owner

Ok thanks, but is avoiding user errors really more important than being compliant with standards... ?

From my perspective, those standards apply to the final output version, but not to the tag itself. There may not be standards for tag naming, but there are at least common patterns, and I would say the v prefix is very common, even if it's not universal. Just as an anecdotal example, the Mypy and Pylint repositories use v, whereas Black and Poetry don't. There are pros and cons to both sides of this trade-off, but I do personally think that keeping the v is a good default behavior.

if one is using dunamai, he would certainly use version identifier only as tag..

I'm someone who uses Dunamai, and my projects have v in the tags 🙃 I think we would need some research first in order to say what most people do.

@cclecle
Copy link
Author

cclecle commented Mar 16, 2023

You are right about the global usage, it is variable on projet / people.
But I thought the point of this lib was about standards, not random developers habits... That's actually why it is used on big projects isn't it ?

I see no good enougth reason to have a non-standardized format mandatory while standardized one are actually not supported by default.
Furthermore this library is advertized as 'standards-compliant version strings' (from readme).
I know it's supposed to be for writing version but again it's shame that the only accepted ones are non-standard by default for reading :-/

By the way, was not asking you if you agree to remove the 'v' bu just to make it optional.

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

2 participants