3.11. Raising Parts of a Version¶
Note
Keep in mind, “raising” the pre-release only will make your complete version lower than before.
For example, having version 1.0.0
and raising the pre-release
will lead to 1.0.0-rc.1
, but 1.0.0-rc.1
is smaller than 1.0.0
.
If you search for a way to take into account this behavior, look for the
method next_version()
in section Increasing Parts of a Version Taking into Account Prereleases.
The semver
module contains the following functions to raise parts of
a version:
bump_major()
: raises the major part and set all other parts to zero. Setprerelease
andbuild
toNone
.bump_minor()
: raises the minor part and setspatch
to zero. Setprerelease
andbuild
toNone
.bump_patch()
: raises the patch part. Setprerelease
andbuild
toNone
.bump_prerelease()
: raises the prerelease part and setbuild
toNone
.bump_build()
: raises the build part.
>>> str(Version.parse("3.4.5-pre.2+build.4").bump_major())
'4.0.0'
>>> str(Version.parse("3.4.5-pre.2+build.4").bump_minor())
'3.5.0'
>>> str(Version.parse("3.4.5-pre.2+build.4").bump_patch())
'3.4.6'
>>> str(Version.parse("3.4.5-pre.2+build.4").bump_prerelease())
'3.4.5-pre.3'
>>> str(Version.parse("3.4.5-pre.2+build.4").bump_build())
'3.4.5-pre.2+build.5'
Likewise the module level functions semver.bump_major()
.
For the methods bump_prerelease()
and bump_build()
it’s possible to pass an empty string or None
.
However, it gives different results:
>>> str(Version.parse("3.4.5").bump_prerelease(''))
'3.4.5-1'
>>> str(Version.parse("3.4.5").bump_prerelease(None))
'3.4.5-rc.1'
An empty string removes any prefix whereas None
is the same as calling
the method without any argument.
If you already have a prerelease, the argument for the method is not taken into account:
>>> str(Version.parse("3.4.5-rc.1").bump_prerelease(None))
'3.4.5-rc.2'
>>> str(Version.parse("3.4.5-rc.1").bump_prerelease(''))
'3.4.5-rc.2'