<commit_before># -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# version.py - version handling for kaa modules
# -----------------------------------------------------------------------------
# Copyright 2005-2012 <NAME>, <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------

# python imports
import math

class Version(object):
    """
    Version information for kaa modules.
    """
    def __init__(self, version):
        """
        Set internal version as string.
        """
        self.version = str(version)

    def __str__(self):
        """
        Convert to string.
        """
        return self.version


    def __repr__(self):
        return str(self)


    def _cmp(self, b):
        """
        Numeric (if possible) or lexical comparison of each verison component.
        """
        b = str(b)  # coerce floats if needed
        parts = max(self.version.count('.'), b.count('.'))
        a = self.version.split('.') + ['0'] * (parts - self.version.count('.'))
        b = b.split('.') + ['0'] * (parts - b.count('.'))
        for ap, bp in zip(a, b):
            if ap.isdigit() and bp.isdigit():
                ap, bp = int(ap), int(bp)
            if ap < bp:
                return -1
            elif ap > bp:
                return 1
        return 0


    def __eq__(self, obj):
        # Don't just do a string compare, because we consider 0.99.0 == 0.99
        return self._cmp(obj) == 0


    # Python 2.
    def __cmp__(self, obj):
        return self._cmp(obj)


    # Python 3
    def __lt__(self, obj):
        return self._cmp(obj) == -1

    def __le__(self, obj):
        return self._cmp(obj) in (-1, 0)

    def __gt__(self, obj):
        return self._cmp(obj) == 1

    def __ge__(self, obj):
        return self._cmp(obj) in (1, 0)<commit_msg>Use setuptools version comparison logic<commit_after># -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# version.py - version handling for kaa modules
# -----------------------------------------------------------------------------
# Copyright 2005-2012 <NAME>, <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------

# python imports
import math
import re

# The following two functions are taken from the setuptools project
# (pkg_resources.py) in order to ensure compatibility with its
# versioning scheme.
#
# Setuptool is written by <NAME> and released under the PSF or
# ZPL licenses.  PSF is GPL-compatible.
component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE)
replace = {'pre':'c', 'preview':'c', '-':'final-', 'rc':'c', 'dev':'@'}.get

def _parse_parts(s):
    for part in component_re.split(s):
        part = replace(part, part)
        if not part or part == '.':
            continue
        if part[:1] in '0123456789':
            yield part.zfill(8)    # pad for numeric comparison
        else:
            yield '*' + part
    yield '*final'  # ensure that alpha/beta/candidate are before final


def _parse(s):
    s = str(s)  # coerce floats if needed
    parts = []
    for part in _parse_parts(s.lower()):
        if part.startswith('*'):
            if part < '*final':   # remove '-' before a prerelease tag
                while parts and parts[-1] == '*final-':
                    parts.pop()
            # remove trailing zeros from each series of numeric parts
            while parts and parts[-1] == '00000000':
                parts.pop()
        parts.append(part)
    return tuple(parts)


class Version(object):
    """
    Version information for kaa modules.

    Version comparison follows the rules defined by `setuptools
    <http://packages.python.org/distribute/setuptools.html#specifying-your-project-s-version>`_.
    """
    def __init__(self, version):
        """
        Set internal version as string.
        """
        self.version = str(version)

    def __str__(self):
        """
        Convert to string.
        """
        return self.version


    def __repr__(self):
        return str(self)


    def __eq__(self, obj):
        return _parse(self.version) == _parse(obj)


    # Python 2.
    def __cmp__(self, obj):
        a = _parse(self.version)
        b = _parse(obj)
        if a == b:
            return 0
        elif a < b:
            return -1
        else:
            return 1


    # Python 3
    def __lt__(self, obj):
        return _parse(self.version) < _parse(obj)

    def __le__(self, obj):
        return _parse(self.version) < _parse(obj)

    def __gt__(self, obj):
        return _parse(self.version) > _parse(obj)

    def __ge__(self, obj):
        return _parse(self.version) >= _parse(obj)
{'fraction_non_alphanumeric': 0.1789763524457402, 'fraction_numerical': 0.016844833171363784, 'mean_word_length': 1.8312700596056855, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '787178', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1642, 'n_words': 627}