bump2version
bump2version copied to clipboard
Optional group in parse regex mangles serialization.
In sphinx's conf.py there are two version numbers: release
which is the major release version and version
which is the full version number. For example:
# docs/conf.py
version = "2.1"
release = "2.1.2"
To deal with the situation where version
has a full version number I make the <patch>
group optional when parsing the line. That way it gets restored back to a major release format.
# setup.cfg
[bumpversion]
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
current_version = 2.1.2
[bumpversion:file:docs/conf.py]
search = release = "{current_version}"
replace = release = "{new_version}"
[bumpversion:file:./docs/conf.py]
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?
serialize = {major}.{minor}
search = version = "{current_version}"
replace = version = "{new_version}"
When this is run with:
bump2version patch
and version contains a full release:
# docs/conf.py
version = "2.1.2"
release = "2.1.2"
docs/conf.py is updated to the following:
version = "version = "2.1""
release = "2.1.3"
Interestingly, if I switch the order in which the version and release are processed then both lines get mangled:
version = "version = "2.1""
release = "version = "2.1""
This only happens if the patch number is present in version, otherwise the optional group in the regex has no ill-effects as long as the version that uses the default regex is processed first.
[UPDATE] You get the same problem by switching the order in which the version numbers are processed:
[bumpversion:file:./docs/conf.py]
parse = (?P<major>\d+)\.(?P<minor>\d+)
serialize = {major}.{minor}
search = version = "{current_version}"
replace = version = "{new_version}"
[bumpversion:file:docs/conf.py]
search = release = "{current_version}"
replace = release = "{new_version}"
I suspect this is a bug caused by search
/replace
not using a proper regex replace, but a string replace.
I don't think there's a known workaround at this point...
I should have noted that the [UPDATE]
works but when the order is reversed it has the same problem as reported initially. So to clarify:
[bumpversion:file:docs/conf.py]
search = release = "{current_version}"
replace = release = "{new_version}"
[bumpversion:file:./docs/conf.py]
parse = (?P<major>\d+)\.(?P<minor>\d+)
serialize = {major}.{minor}
search = version = "{current_version}"
replace = version = "{new_version}"
is a valid workaround for this situation.
Related issue: #71.
Kind of reviving because I have run into an analogous problem with release info.
My .bumpversion.cfg
looks something like this:
[bumpversion]
current_version = 0.0.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<dev>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{dev}{build}
{major}.{minor}.{patch}
[bumpversion:part:dev]
optional_value = _
first_value = _
values =
_
dev
[bumpversion:part:build]
[bumpversion:file:README.md]
search = v{current_version}
replace = v{new_version}
The top line of my README is:
Package Name (v0.0.0)
I'm getting the following error:
bumpversion.exceptions.VersionNotFoundException: Did not find '(v0.0.0-_0)' in file: 'README.md'
As stated above, it looks like utils.ConfiguredFile.contains
method uses a straight string search rather than a regular expression. I assume there are good reasons not to use regular expressions here. If not, could this be changed to use a regular expression?
NOTE: If I change the config file to the following, it works fine. The problem is that any non-version search components produce the same error.
[bumpversion:part:build]
search = {current_version}
replace = {new_version}