mtkennerly / poetry-dynamic-versioning

Plugin for Poetry to enable dynamic versioning based on VCS tags
MIT License
588 stars 36 forks source link

Plugin does not detect git tags? #185

Closed kzych-inpost closed 1 week ago

kzych-inpost commented 1 week ago

Hi, I have my poetry (1.8.3) installed with pipx. I installed the plugin using:

pipx inject poetry "poetry-dynamic-versioning[plugin]

and modified pyproject.toml:

[tool.poetry]
version = "0.0.0" 

...

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend" 

[tool.poetry-dynamic-versioning]

enable = true
vcs = "git"
style = "semver"

Although the plugin works, it does not detect tags, only appends the commit hash:

$ poetry version -s
0.0.0-post.63+978c2c3

$ git tag --points-at HEAD | cat
0.7.4

I would also add, that although I've installed the plugin as mentioned above, straightforward uninstalling leads to an error:

$ pipx uninject poetry "poetry-dynamic-versioning[plugin]"
poetry-dynamic-versioning[plugin] is not in the poetry venv. Skipping.

Only this works:

$ pipx uninject poetry "poetry-dynamic-versioning"
Uninjected package poetry-dynamic-versioning and its dependencies from venv poetry ✨ 🌟 ✨

Do you have any idea what is the cause of this behaviour?

edgarrmondragon commented 1 week ago

You might wanna check your tag format. The default (via Dunamai) is:

(?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>.+))?$ 

So a v prefix is expected. You can change this with the pattern setting.

kzych-inpost commented 1 week ago

Yes, with the v prefix it works indeed!

❯ git tag "v0.7.4"
❯ poetry version -s
0.7.4

However, I have a trouble setting any other pattern (as you suggested) - I keep getting errors:

❯ poetry version -s
Version '^\d+\.\d+\.\d+$' does not conform to the Semantic Versioning style

or after disabling the style = "semver":

❯ poetry version -s
Invalid PEP 440 version: '^\d+\.\d+\.\d+$'
mtkennerly commented 1 week ago

Hi! Could you share your updated config with the pattern field? Since there's a built-in pattern for this, it should look like:

[tool.poetry-dynamic-versioning]
enable = true
pattern = "default-unprefixed"

I would also add, that although I've installed the plugin as mentioned above, straightforward uninstalling leads to an error

The [plugin] optional feature is only used when installing - it's not part of the package name itself. When uninstalling, you just specify the base package name without any optional features.

kzych-inpost commented 1 week ago

Thank you @mtkennerly, after your remark I changed pyproject.toml:

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"
pattern = "default-unprefixed"

and it works like I intended to :)

❯ git tag --points-at HEAD | cat
1.2.3
❯ poetry version -s
1.2.3

I would only suggest to update README.md to make it more obvious for other users?

mtkennerly commented 1 week ago

Added an example :)