Packages

flutils offers the following package utilities:

flutils.bump_version(version, position=-1, pre_release=None)[source]

Increase the version number from a version number string.

New in version 0.3.0

Parameters:
  • version (str) – The version number to be bumped.
  • position (int, optional) – The position (starting with zero) of the version number component to be increased. Defaults to: -1
  • pre_release (str, Optional) – A value of a or alpha will create or increase an alpha version number. A value of b or beta will create or increase a beta version number.
Return type:

str

Returns:

The increased version number

Raises:
  • ValueError – if the given version is an invalid version number.
  • ValueError – if the given position does not exist.
  • ValueError – if the given prerelease is not in: a, alpha, b, beta

A version number consists of two or three dot-separated numeric components, with an optional “pre-release” tag on the end. The pre-release tag consists of the letter ‘a’ (alpha) or ‘b’ (beta) followed by a number. If the numeric components of two version numbers are equal, then one with a pre-release tag will always be deemed earlier (lesser) than one without.

This function works with two and three component version numbers.

The following are valid version numbers:

0.4
0.4.1
0.5a1
0.5b3
0.5
0.9.6
1.0
1.0.4a3
1.0.4b1
1.0.4

The following are examples of invalid version numbers:

1
2.7.2.2
1.3.a4
1.3pl1
1.3c4

Examples

>>> from flutils import bump_version
>>> bump_version('1.2.2')
'1.2.3'
>>> bump_version('1.2.3', position=1)
'1.3.0
>>> bump_version('1.3.4', position=0)
'2.0.0'
>>> bump_version('1.2.3', prerelease='a')
'1.2.4a0'
>>> bump_version('1.2.4a0', pre_release='a')
'1.2.4a1'
>>> bump_version('1.2.4a1', pre_release='beta')
'1.2.4b0'
>>> bump_version('1.2.4a1')
'1.2.4'
>>> bump_version('1.2.4b0')
'1.2.4'
>>> bump_version('2.1.3', position=1, pre_release='a')
'1.3.0a0'
>>> bump_version('1.2.b0', position=0, pre_release='b')
'2.0.0b0'