sugar4.bundle.bundleversion

Validation and normalization of bundle versions.

Instances of NormalizedVersion can be directly compared;

>>> from sugar4.bundle.bundleversion import NormalizedVersion
>>> a = NormalizedVersion('157.3')
>>> b = NormalizedVersion('201.2')
>>> a > b
False
>>> b > a
True

Invalid versions will raise InvalidVersionError.

Valid versions are 1, 1.2, 1.2.3, 1.2.3-peru, and 1.2.3~dfsg.

Invalid versions are:
  • 1.2peru (because the suffix must be preceded with a dash or tilde),

  • 1.2. (because a version can’t end with a period), or

  • 1.02.5 (because a version can’t have a leading zero).

Based on the implementation of PEP 386, but adapted to our numeration schema.

sugar4.bundle.bundleversion.VERSION_RE[source]

regular expression for versions, deprecated, as it is insufficient by itself.

Type:

RegexObject

Attributes

VERSION_RE

Exceptions

InvalidVersionError

A version cannot be normalized, because:

Classes

NormalizedVersion

Normalize a version string.

Module Contents

sugar4.bundle.bundleversion.VERSION_RE[source]
exception sugar4.bundle.bundleversion.InvalidVersionError[source]

Bases: Exception

A version cannot be normalized, because:
  • the object is not a string,

  • the string does not match the regular expression, or

  • the string has a leading zero in a version part.

Initialize self. See help(type(self)) for accurate signature.

class sugar4.bundle.bundleversion.NormalizedVersion(activity_version)[source]

Bases: object

Normalize a version string.

Parameters:

activity_version (str) – the version string

Raises:

InvalidVersionError

parts[source]

the numeric parts of the version after normalization.

Type:

list

parts = [][source]
__str__()[source]
__repr__()[source]
__eq__(other)[source]
__lt__(other)[source]
__ne__(other)[source]
__gt__(other)[source]
__le__(other)[source]
__ge__(other)[source]