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:
prerelease (
str, optional) – Prerelease identifier (e.g., “alpha”, “beta”)prerelease_num (
int, optional) – Prerelease number
- 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:
- property is_prerelease: bool¶
Check if the version is a prerelease
- Returns:
True if the version is a prerelease, False otherwise
- Return type:
- 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:
- 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:
- static parse(*version)¶
Parse version string to Version object
See also
Versionon usageNote
Version such as
1.2or simply1will be parsed as1.2.0and1.0.0respectively.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:
- 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
- __le__(version)¶
Check if version is less than or equal to another version
See also
Versionon usage