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.
Note
This is the reference for Version. For more detailed explanations and usage, visit
the section about semantic versionining in the tutorial
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+b.1")
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+b.1")
assert str(v.major) == "1"
minorο
Get the minor digit.
v = Version("1.2.3.4-alpha.3+b.1")
assert str(v.minor) == "2"
patchο
Get the patch digit.
v = Version("1.2.3.4-alpha.3+b.1")
assert str(v.patch) == "3"
microο
Get the micro digit.
v = Version("1.2.3.4-alpha.3+b.1")
assert str(v.micro) == "4"
preο
Get the pre-release digit.
v = Version("1.2.3.4-alpha.3+b.1")
assert str(v.pre) == "alpha.3"
buildο
Get the build digit.
v = Version("1.2.3.4-alpha.3+b.1")
assert str(v.build) == "b.1"
Note
If any field in the Version contains letters, it will be treated alphabetically, so the relative
order of numbers within those field will not be correct. Make sure to separate with dots the digits,
like alpha.3 and build.1 instead of alpha3 and build1 for correct ordering.
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)