Version class

class verr.Version(*args)

Represents the version number. This class cannot be extended.

Version(ver_str)

Initializes a new instance of the Version class using the specified string to be parsed

Parameters

ver_str (str) – A string containing the major, minor, build, and revision numbers, where each number is delimited with a period character (.).

Example:

ver = Version.parse("1.3")
print(ver) # 1.3
Version(major, minor)

Initializes a new instance of the Verson class using the specified major and minor values.

Parameters
  • major (int or str) – Major part of the version

  • minor (int or str) – Minor part of the version

Example:

ver = Version.parse(1, 3)
print(ver) # 1.3
Version(major, minor, build)

Initializes a new instance of the Verson class using the specified major, minor, and build values.

Parameters
  • major (int or str) – Major part of the version

  • minor (int or str) – Minor part of the version

  • build (int or str) – Build part of the version

Example:

ver = Version.parse(1, 3, 7)
print(ver) # 1.3.7
Version(major, minor, build, revision)

Initializes a new instance of the Verson class with the specified major, minor, build, and revision numbers.

Parameters
  • major (int or str) – Major part of the version

  • minor (int or str) – Minor part of the version

  • build (int or str) – Build part of the version

  • revision (int or str) – Revision part of the version

Example:

ver = Version.parse(1, 3, 7, 22)
print(ver) # 1.3.7.22

Tip

Version instances can be compared using ==, <, <=, >, >=, !=

property build: int

Gets the value of the build component of the version number for the current Version instance.

Returns

build portion of Version

Return type

int

property elements: int

Gets the number of elements in the current instance.

Returns

element count of of 2, 3 or 4

Return type

int

Example

v = Version(11, 22 ,33, 44)
print(v.count) # 4
v = Version(11, 22 ,33)
print(v.count) # 3
v = Version(11, 22)
print(v.count) # 2
v = Version(11)
print(v.count) # 2
print(v.to_str()) # 11.0
property major: int

Gets the value of the major component of the version number for the current Version instnace.

Returns

major portion of Version

Return type

int

property major_revision: int

Gets the high 16 bits of the revision number.

Note

Read-only property Suppose you release an interim version of your application to temporarily correct a problem until you can release a permanent solution. The temporary version does not warrant a new revision number, but it does need to be identified as a different version. In this case, encode the identification information in the high and low 16-bit portions of the 32-bit revision number. Use the revision property to obtain the entire revision number, use the major_revision property to obtain the high 16 bits, and use the minor_revision property to obtain the low 16 bits.

Returns

major_revision portion of Version

Return type

int

property minor: int

Gets the value of the minor component of the version number for the current Version instnace.

Returns

minor portion of Version

Return type

int

property minor_revision: int

Gets the low 16 bits of the revision number.

Note

Read-only property Suppose you release an interim version of your application to temporarily correct a problem until you can release a permanent solution. The temporary version does not warrant a new revision number, but it does need to be identified as a different version. In this case, encode the identification information in the high and low 16-bit portions of the 32-bit revision number. Use the revision property to obtain the entire revision number, use the major_revision property to obtain the high 16 bits, and use the minor_revision property to obtain the low 16 bits.

Returns

minor_revision portion of Version

Return type

int

static parse(input: str)

Converts the string representation of a version number to an equivalent Version instance.

Parameters

input (str) – A string that contains a version number to convert.

Returns

A Version instance that is equivalent to the version number specified in the input parameter

Return type

Version

Rasies FormatError

if input is a bad format.

Rasies ArgumentNullError

if input is None or empty.

Rasies ArgumentOutOfRangeError

if input is out of range.

Rasies ArgumentError

is there is other errors with input

Hex strings are required to be prefixed with 0x.

Tip

Hex strings are not case sensitive.

Attention

Malformed strings are converted as integers as well.

If a string has non-alphnumeric characters then the non-alphnumeric characters are stripped away.

from verr import Version

v = Version.parse('10.1')
print(v) # 10.1

v = Version.parse('10_000.(%2/1)')
print(v) # 10000.21

v = Version.parse('0xab12.0x_1c2d]')
print(v) # 43794.7213

v = Version.parse('"12_^.0x_1c2d]')
# dec 12
# hex 0x1c2d
print(v) # 12.7213
See Also: try_parse()
See Also: Usage: Version.parse

Example:

ver = Version.parse("1.3")
print(ver.major) # 1
print(ver.minor) # 3

ver = Version.parse("1.3.8.97")
print(ver.major) # 1
print(ver.minor) # 3
print(ver.build) # 8
print(ver.revision) # 97
property revision: int

Gets the value of the revision component of the version number for the current Version instnace.

Returns

revision portion of Version

Return type

int

to_str(field_count: Optional[int] = None) str

Get the version as a string delimited by .

Parameters

field_count (int, optional) – Number of fields to return. Must be a value from 1 to elements property value. Default: elements property value.

Example

v = Version(11, 22, 33, 44)
print(v.to_str() == '11.22.33.44') # True
print(v.to_str(field_count=3) == '11.22.33') # True
print(v.to_str(field_count=2) == '11.22') # True
print(v.to_str(field_count=1) == '11') # True
to_tuple(field_count: Optional[int] = None) Tuple[int]

Get the version as a tuple

Parameters

field_count (int, optional) – Number of fields to return. Must be a value from 1 to elements property value. Default: elements property value.

Returns

tuple in integers.

Return type

tuple(int)

Example

v = Version(11, 22, 33, 44)
print(v.to_tuple() == (11, 22, 33, 44)) # True
print(v.to_tuple(field_count=3) == (11, 22, 33)) # True
print(v.to_tuple(field_count=2) == (11, 22)) # True
print(v.to_tuple(field_count=1) == (11,)) # True

v = Version(11, 22, 33)
print(v.to_tuple()) # (11, 22, 33)
print(v.to_tuple(field_count=1)) # (11,)
static try_parse(input: str) Tuple[bool, Union[verr.Version, Exception]]

Converts the string representation of a version number to an equivalent Version instance.

Parameters

input (str) – A string that contains a version number to convert.

Returns

tuple with the first element as bool. first element will be True when parse is a success; Otherwise, first element will be False. When first element is True an instance of the Version will be returned as the second element. When first element is False second element will contain the error that occured that caused the failure.

Return type

tuple(bool, Version) or tuple(bool, Exception)

Hex strings are required to be prefixed with 0x.

Tip

Hex strings are not case sensitive.

Attention

Malformed strings are converted as integers as well.

If a string has non-alphnumeric characters then the non-alphnumeric characters are stripped away.

from verr import Version

v = Version.parse('10.1')
print(v) # 10.1

v = Version.parse('10_000.(%2/1)')
print(v) # 10000.21

v = Version.parse('0xab12.0x_1c2d]')
print(v) # 43794.7213

v = Version.parse('"12_^.0x_1c2d]')
# dec 12
# hex 0x1c2d
print(v) # 12.7213
See Also: parse()
See Also: Usage: Version.try_parse

Example:

v_result = Version.try_parse('2.1.12')
if v_result[0] == True:
    v = v_result[1]
    print(v.major) # 2
    print(v.minor) # 1
    print(v.build) # 17
else:
    print("An Error has occured", v_result[1])