versio package

Submodules

versio.comparable_mixin module

http://regebro.wordpress.com/2010/12/13/python-implementing-rich-comparison-the-correct-way/

class versio.comparable_mixin.ComparableMixin[source]

Bases: object

Mix in this class and implement a _cmpkey() method to make an object comparable.

__class__

alias of type

__delattr__

x.__delattr__(‘name’) <==> del x.name

__eq__(other)[source]

equal

Parameters:other (ComparableMixin) – the instance to compare to
__format__()

default object formatter

__ge__(other)[source]

greater than or equal

Parameters:other (ComparableMixin) – the instance to compare to
__getattribute__

x.__getattribute__(‘name’) <==> x.name

__gt__(other)[source]

greater than

Parameters:other (ComparableMixin) – the instance to compare to
__hash__

x.__hash__() <==> hash(x)

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__le__(other)[source]

less than or equal

Parameters:other (ComparableMixin) – the instance to compare to
__lt__(other)[source]

less than

Parameters:other (ComparableMixin) – the instance to compare to
__ne__(other)[source]

not equal

Parameters:other (ComparableMixin) – the instance to compare to
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

x.__repr__() <==> repr(x)

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__

x.__str__() <==> str(x)

static __subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

versio.version module

A generic version class that supports comparison and version bumping (incrementing by part, for example you may bump the minor part of ‘1.2.3’ yielding ‘1.3.0’).

Four version schemes are included:

* Simple3VersionScheme which supports 3 numerical part versions (A.B.C where A, B, and C are integers)
* Simple4VersionScheme which supports 4 numerical part versions (A.B.C.D where A, B, C, and D are integers)
* Pep440VersionScheme which supports PEP 440 (http://www.python.org/dev/peps/pep-0440/) versions
    (N[.N]+[{a|b|c|rc}N][.postN][.devN])
* PerlVersionScheme which supports 2 numerical part versions where the second part is at least two digits
    (A.BB where A and B are integers and B is zero padded on the left.  For example:  1.02, 1.34, 1.567)

If you don’t specify which version scheme the version instance uses, then it will use the first scheme from the SupportedVersionSchemes list that successfully parses the version string

By default, Pep440VersionScheme is the supported scheme. To change to a different list of schemes, use the Version.set_supported_version_schemes(schemes). For example:

from versio.version_scheme import Simple3VersionScheme, PerlVersionScheme
Version.set_supported_version_schemes([Simple3VersionScheme, PerlVersionScheme])

In addition, you may define your own version scheme by extending VersionScheme.

class versio.version.Version(version_str=None, scheme=None)[source]

Bases: versio.comparable_mixin.ComparableMixin

A version class that supports multiple versioning schemes, version comparisons, and version bumping.

Creates a version instance which is bound to a version scheme.

Parameters:
  • version_str (str or None) – the initial version as a string
  • scheme – the version scheme to use to parse the version string or None to try all supported

version schemes. :type scheme: VersionScheme or None

__class__

alias of type

__delattr__

x.__delattr__(‘name’) <==> del x.name

__eq__(other)

equal

Parameters:other (ComparableMixin) – the instance to compare to
__format__()

default object formatter

__ge__(other)

greater than or equal

Parameters:other (ComparableMixin) – the instance to compare to
__getattribute__

x.__getattribute__(‘name’) <==> x.name

__gt__(other)

greater than

Parameters:other (ComparableMixin) – the instance to compare to
__hash__

x.__hash__() <==> hash(x)

__init__(version_str=None, scheme=None)[source]

Creates a version instance which is bound to a version scheme.

Parameters:
  • version_str (str or None) – the initial version as a string
  • scheme – the version scheme to use to parse the version string or None to try all supported

version schemes. :type scheme: VersionScheme or None

__le__(other)

less than or equal

Parameters:other (ComparableMixin) – the instance to compare to
__lt__(other)

less than

Parameters:other (ComparableMixin) – the instance to compare to
__ne__(other)

not equal

Parameters:other (ComparableMixin) – the instance to compare to
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

x.__repr__() <==> repr(x)

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__()[source]

Render to version to a string.

Returns:the version as a string.
Return type:str
static __subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

bump(field_name=None, sub_index=-1)[source]

Bump the given version field by 1. If no field name is given, then bump the least significant field.

Parameters:
  • field_name (object) – the field name that matches one of the scheme’s fields
  • sub_index (int) – index in field
Returns:

True on success

Return type:

bool

classmethod set_supported_version_schemes(schemes)[source]

Set the list of version schemes used when parsing a string.

Parameters:schemes – list of version schemes.
supported_version_schemes = [<versio.version_scheme.VersionScheme object at 0x7fbe7452bc90>]

versio.version_scheme module

This class defines the version scheme used by Version.

A version scheme consists of a:

* name,
* regular expression used to parse the version string,
* the regular expression flags to use (mainly to allow verbose regexes),
* format string used to reassemble the parsed version into a string,
* optional list of field types (if not specified, assumes all fields are strings),
* list of field names used for accessing the components of the version.
* an optional subfield dictionary with the key being a field name and the value being a list of sub field names.
  For example, in the Pep440VersionScheme, the "Release" field may contain multiple parts, so we use
  subfield names for the parts.  Say we have a version of "1.2.3rc1", the "1.2.3" is the release field, then
  "1" is the "major" subfield, "2" is the "minor" subfield, and "3" is the "tiny" subfield.
* a "clear" value used to set the field values to the right of the field being bumped,
* a sequence dictionary where the keys are the field names and the values are a list of allowed values.
  The list must be in bump order.  Bumping the last value in the list has no effect.

Note, you need to manually maintain consistency between the regular expression, the format string, the optional field types, and the fields list. For example, if your version scheme has N parts, then the regular expression should match into N groups, the format string should expect N arguments to the str.format() method, and there must be N unique names in the fields list.

class versio.version_scheme.VersionScheme(name, parse_regex, clear_value, format_str, format_types=None, fields=None, subfields=None, parse_flags=0, compare_order=None, compare_fill=None, sequences=None, description=None)[source]

Bases: object

Describe a versioning scheme

A versioning scheme is defined when an instance is created. :param name: the name of the versioning scheme. :type name: str :param parse_regex: the regular expression that parses the version from a string. :type parse_regex: str :param clear_value: the value that the fields to the right of the bumped field get set to. :type clear_value: str or None :param format_str: the format string used to reassemble the version into a string :type format_str: str :param format_types: a list of types used to case the version parts before formatting. :type format_types: list of type :param fields: the list of field names used to access the individual version parts :type fields: list of str :param subfields: a dictionary of field name/list of subfield names use to access parts within a version part :type subfields: dict :param parse_flags: the regular expression flags to use when parsing a version string :type parse_flags: int :param compare_order: The optional list containing the order to compare the parts. :type compare_order: list[int] or None :param compare_fill: The optional list containing the fill string to use when comparing the parts. :type compare_fill: list[str] or None :param sequences: a dictionary of field name/list of values used for sequencing a version part :type sequences: dict :param description: the description of the versioning scheme :type description: str

__class__

alias of type

__delattr__

x.__delattr__(‘name’) <==> del x.name

__format__()

default object formatter

__getattribute__

x.__getattribute__(‘name’) <==> x.name

__hash__

x.__hash__() <==> hash(x)

__init__(name, parse_regex, clear_value, format_str, format_types=None, fields=None, subfields=None, parse_flags=0, compare_order=None, compare_fill=None, sequences=None, description=None)[source]

A versioning scheme is defined when an instance is created. :param name: the name of the versioning scheme. :type name: str :param parse_regex: the regular expression that parses the version from a string. :type parse_regex: str :param clear_value: the value that the fields to the right of the bumped field get set to. :type clear_value: str or None :param format_str: the format string used to reassemble the version into a string :type format_str: str :param format_types: a list of types used to case the version parts before formatting. :type format_types: list of type :param fields: the list of field names used to access the individual version parts :type fields: list of str :param subfields: a dictionary of field name/list of subfield names use to access parts within a version part :type subfields: dict :param parse_flags: the regular expression flags to use when parsing a version string :type parse_flags: int :param compare_order: The optional list containing the order to compare the parts. :type compare_order: list[int] or None :param compare_fill: The optional list containing the fill string to use when comparing the parts. :type compare_fill: list[str] or None :param sequences: a dictionary of field name/list of values used for sequencing a version part :type sequences: dict :param description: the description of the versioning scheme :type description: str

static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

x.__repr__() <==> repr(x)

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__

x.__str__() <==> str(x)

static __subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

parse(version_str)[source]

Parse the version using this scheme from the given string. Returns None if unable to parse.

Parameters:version_str – A string that may contain a version in this version scheme.
Returns:the parts of the version identified with the regular expression or None.
Return type:list of str or None

Module contents

versio Packages

versio Classes

versio Inheritance Diagrams

Inheritance diagram of versio.comparable_mixin

Inheritance diagram of versio.version

Inheritance diagram of versio.version_scheme

Table Of Contents

Previous topic

versio

This Page