bump2version icon indicating copy to clipboard operation
bump2version copied to clipboard

Version interpolation does not act as expected when using format modifiers

Open software-opal opened this issue 6 years ago • 3 comments

I have a project that is using yy.mm for version numbers; and I would like the version to always have a leading zero in the month field. I had initially tried to do this using the following fragment; with no success:

serialize =
	{major}.{minor:02}.{patch}
	{major}.{minor:02}

On closer inspection it appears as though none of the string or integer formatting options work, I've also tried {minor!s:0>2}(produces 19.<bumpversion.VersionPart:NumericVersionPartConfiguration:4>, and {minor:0>2}(produces 19.4) to no avail.

software-opal avatar May 05 '19 21:05 software-opal

From a very quick look it seems that the easiest approach fix for this is to use the string formatting parameters in bumpversion.version_part:VersionPart.__format__.

This does lead to an interesting problem however. Because self.value is a string, the integer formatting options will cause an error. One option is to just make people use string formatting; but that feels a bit dirty, especially given it'll be surprising to many users. The other option is to try to parse the value as an integer, use that integer, and if that fails fall back to string formatting.

I'm happy to propose a patch, given it doesn't seem like it's too much work.

software-opal avatar May 05 '19 21:05 software-opal

open to a patch!

c4urself avatar Aug 24 '19 23:08 c4urself

I've been running in to this issue as well. I like @software-opal's idea to try to format the value as a string then fall back to an int. I'll go ahead and open a PR since it doesn't seem like there has been much movement on this

jessereitz avatar May 09 '20 04:05 jessereitz