From 2cbaf156045769b54150e4d4c3c1071f164a16fb Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 21 Nov 2016 10:24:17 +0100 Subject: 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 Reviewed-By: Martin Basti Reviewed-By: Martin Babinsky --- ipapython/ipautil.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ipapython') diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index f7d75376b..7d3429493 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -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 "".format(*self) + + def __getnewargs__(self): + return str(self) + + @property + def major(self): + return self[0] + + @property + def minor(self): + return self[1] -- cgit