Packages

flutils offers the following package utilities:

Version Numbers

In flutils a version number consists of two or three dot-separated numeric components, with an optional “pre-release” tag on the right-component. 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.

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

The following function is designed to work with version numbers formatted as described above:

bump_version(version, position=2, pre_release=None)[source]

Increase the version number from a version number string.

New in version 0.3

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: 2

  • 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.

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

  • ValueError – if trying to ‘major’ part, of a version number, to a pre-release version.

Return type

str

  • The increased version number.

Examples

>>> from flutils.packages import bump_version
>>> bump_version('1.2.2')
'1.2.3'
>>> bump_version('1.2.3', position=1)
'1.3'
>>> bump_version('1.3.4', position=0)
'2.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='b')
'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')
'2.2a0'
>>> bump_version('1.2b0', position=2)
'1.2.1'