anybox.buildbot.capability.version module

class anybox.buildbot.capability.version.Version(*version, **kw)[source]

Bases: object

Enhanced version tuple, understanding some suffixes.

For now, the only recognized suffix is ‘devel’. Any devel version is lower than any non-devel

>>> Version(8, 4)
Version(8, 4)
>>> Version(9, 2, suffix='devel')
Version(9, 2, suffix='devel')
>>> Version(9, 1) > Version(8,4)
True
>>> Version(9, 2, suffix='devel') > Version(9, 2)
False
>>> Version(9, 1) >= Version(8, 4)
True
>>> Version(9, 1) >= Version(9, 1)
True
>>> Version(9, 2, suffix='devel') >= Version(9, 2)
False
>>> Version(9, 2, suffix='devel') >= Version(9, 2, suffix='devel')
True
>>> Version(9, 1) < Version(9, 2, suffix='devel')
True
>>> Version(9, 1) <= Version(9, 1)
True
>>> Version(9, 1, suffix='devel') < Version(9, 1)
True

suffix is the only accepted keyword argument (the use of variable keyword arguments is forced upon us by the variable number of positional ones):

>>> try: v = Version(9, 1, prefix='devel')

... except ValueError: pass

classmethod parse(as_string)[source]

Instantiate from a string representation.

>>> print repr(Version.parse('9.1'))
Version(9, 1)
>>> Version.parse('9.2-devel')
Version(9, 2, suffix='devel')

A special case that’s a convenience, if no version is supplied, we forward that, avoiding a cumbersome ‘is None’ case to some callers:

>>> Version.parse(None) is None
True

The parse method and str() are mutually inverse >>> str(Version.parse(‘2.6’)) ‘2.6’ >>> str(Version.parse(‘1.2-alpha’)) ‘1.2-alpha’ >>> Version.parse(str(Version(9, 1))) Version(9, 1) >>> Version.parse(str(Version(1, 2, suffix=’alpha’))) Version(1, 2, suffix=’alpha’)

The only recognized suffix separator is the dash (that may change in the future). Having several of them is an error:

>>> try: vf = Version.parse('8.4-devel-wild')

... except VersionParseError, exc: exc.args[0] ‘8.4-devel-wild’

class anybox.buildbot.capability.version.VersionFilter(capability, criteria)[source]

Bases: object

Represent a simple version filter.

The simplest way to instantiate is to call the parse() classmethod:

>>> vf = VersionFilter.parse('pg >= 9.1 < 9.3')

Then we can tell if a given version matches:

>>> vf.match(Version.parse('9.2'))
True
>>> vf.match(Version.parse('8.4'))
False
>>> vf.match(Version.parse('9.3-devel'))
True
>>> vf.match(Version.parse('9.4'))
False

With more complicated criteria:

>>> vf = VersionFilter.parse('pg >= 9.2-devel OR == 8.4-special')
>>> vf.match(Version.parse('9.2'))
True
>>> vf.match(Version.parse('9.1'))
False
>>> vf.match(Version.parse('8.4-special'))
True

For uniformity, absence of criteria is also accepted, and of course matches any version:

>>> vf = VersionFilter.parse('rabbitmq')
>>> vf.match(Version.parse('6.6.6-any'))
True

With errors:

>>> try: vf = VersionFilter.parse('pg 8.4')
... except VersionParseError, exc: exc.args[0]
'8.4'

On a version filter, str() gives back something meant for parse():

>>> str(VersionFilter.parse('rabbitmq'))
'rabbitmq'
>>> str(VersionFilter.parse('pg >= 9.1 < 9.3'))
'pg >= 9.1 AND < 9.3'
>>> str(VersionFilter.parse('pg >= 9.2-devel OR == 8.4-special'))
'pg >= 9.2-devel OR == 8.4-special'

while repr() follows the general convention to be Python code:

>>> repr(VersionFilter.parse('pg >= 9 < 9.3'))
"VersionFilter('pg', ('AND', ('>=', Version(9)), ('<', Version(9, 3))))"
boolean_match(version, criteria)[source]
classmethod boolean_parse(reqline)[source]
match(version)[source]

Tell if the given version matches the criteria.

classmethod parse(as_string)[source]

Parse the filter from a requirement line.

ANDs are implicit between operands, OR are not and have lower precedence. >>> vf = VersionFilter.parse( ... ‘postgresql <= 9.2 > 8.4 OR == 8.4-patched’) >>> vf == VersionFilter( ... ‘postgresql’, ... (‘OR’, ... (‘AND’, (‘<=’, Version(9, 2)), (‘>’, Version(8, 4))), ... (‘==’, Version(8, 4, suffix=’patched’)))) True

exception anybox.buildbot.capability.version.VersionParseError[source]

Bases: exceptions.ValueError

Dedicated exception for version and version filter parsing errors.

Arguments should be
  • string that can’t be parsed
  • reason
>>> VersionParseError('asds', 'not a number')
VersionParseError('asds', 'not a number')

This Page