mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-07-29 15:55:47 -05:00
Replace LooseVersion
pylint is having a hard time with distutils.version in tox's virtual envs. virtualenv uses some tricks to provide a virtual distutils package, pylint can't cope with. https://github.com/PyCQA/pylint/issues/73 suggests to use pkg_resources instead. pkg_resources' version parser has some more benefits, e.g. PEP 440 conformity. But pkg_resources.parse_version() is a heavy weight solution with reduced functionality, e.g. no access to major version. For API_VERSION and plugin version we can use a much simpler and faster approach. https://fedorahosted.org/freeipa/ticket/6468 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Martin Basti <mbasti@redhat.com> Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
committed by
Martin Babinsky
parent
526bcea705
commit
2cbaf15604
@@ -1533,3 +1533,35 @@ def escape_seq(seq, *args):
|
||||
"""
|
||||
|
||||
return tuple(a.replace(seq, u'\\{}'.format(seq)) for a in args)
|
||||
|
||||
|
||||
class APIVersion(tuple):
|
||||
"""API version parser and handler
|
||||
|
||||
The class is used to parse ipapython.version.API_VERSION and plugin
|
||||
versions.
|
||||
"""
|
||||
__slots__ = ()
|
||||
|
||||
def __new__(cls, version):
|
||||
major, dot, minor = version.partition(u'.')
|
||||
major = int(major)
|
||||
minor = int(minor) if dot else 0
|
||||
return tuple.__new__(cls, (major, minor))
|
||||
|
||||
def __str__(self):
|
||||
return '{}.{}'.format(*self)
|
||||
|
||||
def __repr__(self):
|
||||
return "<APIVersion('{}.{}')>".format(*self)
|
||||
|
||||
def __getnewargs__(self):
|
||||
return str(self)
|
||||
|
||||
@property
|
||||
def major(self):
|
||||
return self[0]
|
||||
|
||||
@property
|
||||
def minor(self):
|
||||
return self[1]
|
||||
|
||||
Reference in New Issue
Block a user