http://regebro.wordpress.com/2010/12/13/python-implementing-rich-comparison-the-correct-way/
Bases: object
Mix in this class and implement a _cmpkey() method to make an object comparable.
alias of type
x.__delattr__(‘name’) <==> del x.name
default object formatter
greater than or equal
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
x.__init__(...) initializes x; see help(type(x)) for signature
less than or equal
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
size of object in memory, in bytes
x.__str__() <==> str(x)
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).
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.
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 schemes. :type scheme: VersionScheme or None
alias of type
x.__delattr__(‘name’) <==> del x.name
equal
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
default object formatter
greater than or equal
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
x.__getattribute__(‘name’) <==> x.name
greater than
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
x.__hash__() <==> hash(x)
Creates a version instance which is bound to a version scheme.
Parameters: |
|
---|
version schemes. :type scheme: VersionScheme or None
less than or equal
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
less than
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
not equal
Parameters: | other (ComparableMixin) – the instance to compare to |
---|
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
size of object in memory, in bytes
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 the given version field by 1. If no field name is given, then bump the least significant field.
Parameters: | |
---|---|
Returns: | True on success |
Return type: | bool |
Set the list of version schemes used when parsing a string.
Parameters: | schemes – list of version schemes. |
---|
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.
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
alias of type
x.__delattr__(‘name’) <==> del x.name
default object formatter
x.__getattribute__(‘name’) <==> x.name
x.__hash__() <==> hash(x)
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
helper for pickle
helper for pickle
x.__repr__() <==> repr(x)
x.__setattr__(‘name’, value) <==> x.name = value
size of object in memory, in bytes
x.__str__() <==> str(x)
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 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 |