c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.05k stars 135 forks source link

Adds zero in text files, commit message/tag is fine #182

Open luckydonald opened 3 years ago

luckydonald commented 3 years ago

For reproduction the repo luckydonald/pytgbot can be can be checked out at commit 2b35b5901df9d0aa6335d65bfca3dccf3477e8c9.

The config is quite easy,

[bumpversion]
current_version = 5.0.0
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+)(\.(?P<internal>\d+))?)?
serialize =
    {major}.{minor}.{patch}.{internal}
    {major}.{minor}.{patch}
    {major}.{minor}

[bumpversion:file:pytgbot/__init__.py]

[bumpversion:file:setup.py]

[bumpversion:file:README.md]

If I now run

$ bump2version internal

I'll end up with diffs like

-   name='pytgbot', version="5.0.0",
+   name='pytgbot', version="5.0.0.1.0",

For some reason it adds an unneeded .0 at the end, which it shouldn't.

Funnily enough, the version in the commit message, the .bumpversion file and the tag is correctly 5.0.0.1.

Why would a few of those do completely different things?

I see no reason how it can get that wrong:

>>> old_version = '5.0.0'  # via config file
>>> new_version = '5.0.0.1'  # git message shows it is able to calculate that properly

>>> input = "version=\"5.0.0\""
>>> output = input.replace(old_version, new_version)  # replace 5.0.0 with 5.0.0.1

>>> output
'version="5.0.0.1"'
# now how would that say "5.0.0.1.0"?!?
florisla commented 3 years ago

This bug is caused by bump2version's naive strategy of replacing. I think #71 is another symptom.

When replacing 5.0.0 with 5.0.0.1, 5.0.0 is first serialized. This results in 5.0.

That is what's being replaced with 5.0.0.1; the .0 suffix remains in place.

bump2version should not replace the serialized version number, it should replace the version number which is present.

To work around this, you should use the shortest possible serialization format in your files. Write 5.0, not 5.0.0.

florisla commented 3 years ago

Another way to think about this:

One could argue that this is not a bug.

Your config says that "5.0" is a valid version string for all your files, and instructs bump2version to replace it with new_version in your file.

But it could -- at least -- warn the user that current_version = 5.0.0 is not the canonical (shortest possible) serialization.

luckydonald commented 3 years ago

bump2version should not replace the serialized version number, it should replace the version number which is present.

Yes, that would be the correct behaviour.

Your config says that "5.0" is a valid version string for all your files, and instructs bump2version to replace it with new_version in your file.

So the regex must be greedy to include the last .0 as well?