Versionο
This is a helper class to work with versions, it splits the version string based on dots and hyphens. It exposes all the version components as properties and offers total ordering through compare operators.
compiler_lower_than_12 = Version(self.settings.compiler.version) < "12.0"
is_legacy = Version(self.version) < 2
- class Version(value, qualifier=False)ο
This is NOT an implementation of semver, as users may use any pattern in their versions. It is just a helper to parse β.β or β-β and compare taking into account integers when possible
Attributesο
The Version class offers ways to access the different parts of the version number:
mainο
Get all the main digits.
v = Version("1.2.3.4-alpha.3+b1")
assert [str(i) for i in v.main] == ['1', '2', '3', '4', '5']
majorο
Get the major digit.
v = Version("1.2.3.4-alpha.3+b1")
assert str(v.major) == "1"
minorο
Get the minor digit.
v = Version("1.2.3.4-alpha.3+b1")
assert str(v.minor) == "2"
patchο
Get the patch digit.
v = Version("1.2.3.4-alpha.3+b1")
assert str(v.patch) == "3"
microο
Get the micro digit.
v = Version("1.2.3.4-alpha.3+b1")
assert str(v.micro) == "4"
preο
Get the pre-release digit.
v = Version("1.2.3.4-alpha.3+b1")
assert str(v.pre) == "alpha.3"
buildο
Get the build digit.
v = Version("1.2.3.4-alpha.3+b1")
assert str(v.build) == "b1"
Methodsο
The Version class implements the following methods:
in_rangeο
Check if the version is in the specified range.
assert Version("1.0").in_range(">=1.0 <2")
assert not Version("1.0").in_range(">1.0 <2")
assert not Version("1.0-rc").in_range(">=1.0 <2.0")
assert Version("1.0-rc").in_range(">=1.0 <2.0", resolve_prerelease=True)