Version

This module provides a Version class for comparing versions

It is mainly used in npc.BasePlugin to check if the plugin has a newer version available. The version can be compared using the comparison operators such as ==, !=, <, <=, >, and >=.

Example

old = Version(1, 2, 3)
new = Version.parse("1.2.4")

new > old
# True
class npc.Version(major, minor, patch, prerelease=None, prerelease_num=None)

Version class for comparing versions with semantic versioning support

Example

Version(1, 2, 3, "alpha", 1)
# Version(1.2.3a1)

Version.parse("1.2.3a1")
# Version(1.2.3a1)

Version.parse("v1.2.3")
# Version(1.2.3)

Version.parse("1.2.3") == Version(1, 2, 3)
# True

Version.parse("1.2.3") < Version(1, 2, 4)
# True

Version.parse("1.2.3") > Version(1, 2, 4)
# False

Changed in version 0.3.0: Add support for proper semantic versioning (alpha and beta releases)

Parameters:
major

Major version

Type:

int

minor

Minor version

Type:

int

patch

Patch version

Type:

int

prerelease

Prerelease identifier

Type:

str, optional

prerelease_num

Prerelease number

Type:

int, optional

Properties:

astuple (tuple): Tuple representation of the version is_prerelease (bool): True if the version is a prerelease is_alpha (bool): True if the version is an alpha release is_beta (bool): True if the version is a beta release

property astuple: Tuple[int, int, int, str | None, int | None]

Tuple representation of the version

Returns:

Tuple of version parts

Return type:

tuple

property is_prerelease: bool

Check if the version is a prerelease

Returns:

True if the version is a prerelease, False otherwise

Return type:

bool

property is_alpha: bool

Check if the version is an alpha release

Returns:

True if the version is an alpha release, False otherwise

Return type:

bool

property is_beta: bool

Check if the version is a beta release

Returns:

True if the version is a beta release, False otherwise

Return type:

bool

static parse(*version)

Parse version string to Version object

See also

Version on usage

Note

Version such as 1.2 or simply 1 will be parsed as 1.2.0 and 1.0.0 respectively.

Changed in version 0.3.5: Properly parse version strings with alpha, beta, and dev releases. Fixing recognition of dev version in config.

Parameters:

*version (str, int) – Version string or tuple of version parts. If length is 1, it will be split by “.” and parsed as version parts

Returns:

Version object

Return type:

Version

Raises:

ValueError – If version cannot be parsed

__str__()

String representation of the version

See also

Version.__repr__() for representation

__repr__()

Representation of the version

See also

Version.__str__() for string representation

__eq__(version)

Check if versions are equal

See also

Version on usage

Parameters:

version (Version) – Version object

Returns:

True if versions are equal, False otherwise

Return type:

bool

__lt__(version)

Check if version is less than another version

See also

Version on usage

Parameters:

version (Version) – Version object

Returns:

True if version is less than the other version, False otherwise

Return type:

bool

__le__(version)

Check if version is less than or equal to another version

See also

Version on usage

Parameters:

version (Version) – Version object

Returns:

True if version is less than or equal to the other version, False otherwise

Return type:

bool

__gt__(version)

Check if version is greater than another version

See also

Version on usage

Parameters:

version (Version) – Version object

Returns:

True if version is greater than the other version, False otherwise

Return type:

bool

__ge__(version)

Check if version is greater than or equal to another version

See also

Version on usage

Parameters:

version (Version) – Version object

Returns:

True if version is greater than or equal to the other version, False otherwise

Return type:

bool

__ne__(version)

Check if versions are not equal

See also

Version on usage

Parameters:

version (Version) – Version object

Returns:

True if versions are not equal, False otherwise

Return type:

bool