diff options
| author | Christian Heimes <cheimes@redhat.com> | 2016-11-21 10:24:17 +0100 |
|---|---|---|
| committer | Martin Babinsky <mbabinsk@redhat.com> | 2016-11-24 15:46:40 +0100 |
| commit | 2cbaf156045769b54150e4d4c3c1071f164a16fb (patch) | |
| tree | e56ed216116635fb02adae9a58fc8b6e2e6ce1d5 /ipapython | |
| parent | 526bcea705d04895aa6b09bce996ac340783d1d0 (diff) | |
| download | freeipa-2cbaf156045769b54150e4d4c3c1071f164a16fb.tar.gz freeipa-2cbaf156045769b54150e4d4c3c1071f164a16fb.tar.xz freeipa-2cbaf156045769b54150e4d4c3c1071f164a16fb.zip | |
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>
Diffstat (limited to 'ipapython')
| -rw-r--r-- | ipapython/ipautil.py | 32 |
1 files changed, 32 insertions, 0 deletions
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 "<APIVersion('{}.{}')>".format(*self) + + def __getnewargs__(self): + return str(self) + + @property + def major(self): + return self[0] + + @property + def minor(self): + return self[1] |
