Version#
Version
#
This class implements an order relation between version strings. Version strings can contain the usual alphanumeric characters (A-Za-z0-9), separated into segments by dots and underscores. Empty segments (i.e. two consecutive dots, a leading/trailing underscore) are not permitted. An optional epoch number - an integer followed by '!' - can precede the actual version string (this is useful to indicate a change in the versioning scheme itself). Version comparison is case-insensitive.
epoch: Optional[str]
property
#
Gets the epoch of the version or None
if the epoch was not defined.
Examples#
has_local: bool
property
#
Returns true if this version has a local segment defined.
The local part of a version is the part behind the (optional) +
.
Examples#
is_dev: bool
property
#
Returns true if the version contains a component name "dev", dev versions are sorted before non-dev version.
Examples#
segment_count: int
property
#
Returns the number of segments in the version. This does not include epoch or local segment of the version
Examples#
__ge__(other)
#
Returns True if this instance should be ordered after or at the same location
as other
.
Examples#
__le__(other)
#
Returns True if this instance should be ordered before or at the same
location as other
.
Examples#
__repr__()
#
__str__()
#
as_major_minor()
#
Returns the major and minor segments from the version.
Requires a minimum of 2 segments in version to be split
into major and minor, returns None
otherwise.
Examples#
bump_last()
#
Returns a new version where the last segment of this version has been bumped.
Examples#
bump_major()
#
Returns a new version where the major segment of this version has been bumped.
Examples#
bump_minor()
#
Returns a new version where the minor segment of this version has been bumped.
Examples#
bump_patch()
#
Returns a new version where the patch segment of this version has been bumped.
Examples#
bump_segment(index)
#
Returns a new version where the last segment of this version has been bumped.
Examples#
compatible_with(other)
#
Checks if this version is compatible with other version. Minor versions changes are compatible with older versions, major version changes are breaking and will not be compatible.
Examples#
extend_to_length(length)
#
Returns a new version that is extended with 0s
to the specified length.
Examples#
local_segments()
#
Returns a list of local segments of the version. It does not contain the non-local segment of the version.
Examples#
pop_segments(n=1)
#
Pops n
number of segments from the version and returns
the new version. Raises InvalidVersionError
if version
becomes invalid due to the operation.
Examples#
>>> v = Version('2!1.0.1')
>>> v.pop_segments() # `n` defaults to 1 if left empty
Version("2!1.0")
>>> v.pop_segments(2) # old version is still usable
Version("2!1")
>>> v.pop_segments(3) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
exceptions.InvalidVersionException: new Version must have atleast 1 valid
segment
>>>
remove_local()
#
Returns a new version where the local segment of the version has been removed. Leaves the version unchanged if it does not have a local segment.
Examples#
segments()
#
Returns a list of segments of the version. It does not contain the local segment of the version.