support.semver – Semantic Versioning Support¶
This module defines functions and classes for a semantic versioning (aka SemVer) support.
The parser match the semantic versioning specification 2.0.0.
Public Classes¶
This module has only one public class.
Objects reference¶
This section details the objects defined in this module.
- class support.semver.SemVer(version_string)¶
Bases:
objectSemVer parser class.
- Parameters
version_string (str) – The version string matching the semantic versioning specification. Otherwise a ValueError exception is raised.
- Raises
TypeError – Parameters type mismatch.
ValueError – Version string do not match the specification rules.
- Special Methods
This class has a number of special methods, listed below in alphabetical order, to make the version comparison.
- Using SemVer…
The main purpose of this class is to compute comparison between version identifier as described in semantic versioning specification. So the using is limited to create class instance with the version identifier string and use the comparison operator as shown in the below example.
>>> import lapptrack.cots.semver as semver >>> v1 = semver.SemVer("1.0.0") >>> v2 = semver.SemVer("2.0.0") >>> v1 < v2 True >>> v1 = semver.SemVer("1.0.0-alpha") >>> v2 = semver.SemVer("1.0.0-beta") >>> v1 > v2 False >>> v1 = semver.SemVer("1.0.0") >>> v2 = semver.SemVer("1.0.0") >>> v1 < v2 False >>> v1 == v2 True
- __eq__(other)¶
Rich comparison method, return self == other.
- __gt__(other)¶
Rich comparison method, return self > other.
- __init__(version_string)¶
- __lt__(other)¶
Rich comparison method, return self < other.
- __ne__(other)¶
Rich comparison method, return self != other.
- __repr__()¶
Compute the string representation of the SemVer object.
- Returns
- the version string which can be used to recreate the
SemVer object.
- Return type
- _parse(version_string)¶
Parse the version string.
- Parameters
version_string (str) – The version string matching the semantic versioning specification. Otherwise a ValueError exception is raised.
- Raises
TypeError – Parameters type mismatch.
ValueError – Version string do not match the specification rules.
- __hash__ = None¶
- __weakref__¶
list of weak references to the object (if defined)
- property major¶
Get the major version number.
- Returns
The version number with only the major number.
- Return type
- property minor¶
Get the minor version number.
- Returns
The version number with the major and the minor number .
- Return type
- property patch¶
Get the patch version number.
- Returns
- The version number with the major, the minor and the patch
number.
- Return type
Functions reference¶
This section details the specific functions used in this module.
- support.semver._comp_version(version1, version2)¶
Compare two version identifiers limited to the major, minor and patch fields.
The rule # 11 specify the precedence rules for comparing version identifiers (i.e.
1.0.0 < 2.0.0 < 2.1.0 < 2.1.1).- Parameters
- Returns
-1, 0 or 1 as below
-1:
version1is lower thanversion20:
version1is equal toversion21:
version1is greater thanversion2
- Return type
- Raises
TypeError – Parameters type mismatch.
- support.semver._comp_prerelease(prerelease1, prerelease2)¶
Compare two pre-release version identifiers.
The rule # 11 specify the precedence rules for comparing pre-release version identifiers (i.e. 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0).
- Parameters
- Returns
-1, 0 or 1 as below
-1:
prerelease1is lower thanprerelease20:
prerelease1is equal toprerelease21:
prerelease1is greater thanprerelease2
- Return type
- Raises
TypeError – Parameters type mismatch.
- support.semver._compstr(string1, string2)¶
Compare two string either numerically or lexically.
If the two string are constituted of only digits, there are compared numerically and strings with letters or hyphens are compared lexically in ASCII sort order. So numeric string always have lower precedence than non-numeric string.
Example
‘2’ < ‘11’``‘ab’ < ‘abc’, ‘ab’ < ‘ac’, ‘AC’ < ‘ac’‘12’ < ‘abc’- Parameters
- Returns
-1, 0 or 1 as below
-1:
string1is lower thanstring20:
string1is equal tostring21:
string1is greater thanstring1
- Return type
- Raises
TypeError – Parameters type mismatch.