semver
The semver module provides functions for working with semantic versioning.
The core functionality is provided by github.com/blang/semver/v4.
Functions
compare
Function signature
compare(v1 int, v2 int) intCompares v1 and v2. Returns -1 if v1 is less than v2, 0 if both are equal, 1 if v1 is greater than v2.
Example
>>> import semver
>>> semver.compare("1.2.3", "1.2.4")
-1major
Function signature
major(version string) intReturns the major version of the given version string.
Example
>>> import semver
>>> semver.major("1.2.3")
1minor
Function signature
minor(version string) intReturns the minor version of the given version string.
Example
>>> import semver
>>> semver.minor("1.2.3")
2patch
Function signature
patch(version string) intReturns the patch version of the given version string.
Example
>>> import semver
>>> semver.patch("1.2.3")
3build
Function signature
build(version string) stringReturns the build version of the given version string.
Example
>>> import semver
>>> semver.build("1.2.3+build")
"build"pre
Function signature
pre(version string) stringPre returns the pre-release version of the given version string.
Example
>>> import semver
>>> semver.pre("1.2.3-pre")
"pre"validate
Function signature
validate(version string) boolReturns an error if the version isn't valid.
Example
>>> import semver
>>> semver.validate("1.2.3invalid")
Invalid character(s) found in patch number "3invalid"parse
Function signature
parse(version string) mapParses the given version string and returns a map with the major, minor, patch, pre-release, and build versions.
Example
>>> import semver
>>> semver.parse("1.2.3-pre+build")
{
"major": 1,
"minor": 2,
"patch": 3,
"pre": "pre",
"build": "build"
}equals
Function signature
equals(v1 string, v2 string) boolReturns whether v1 and v2 are equal.
Example
>>> import semver
>>> semver.equals("1.2.3", "1.2.3")
true