

def compare_versions(x, y):
    "\n    Expects 2 strings in the format of 'X.Y.Z' where X, Y and Z are\n    integers. It will compare the items which will organize things\n    properly by their major, minor and bugfix version.\n    ::\n\n        >>> my_list = ['v1.13', 'v1.14.2', 'v1.14.1', 'v1.9', 'v1.1']\n        >>> sorted(my_list, cmp=compare_versions)\n        ['v1.1', 'v1.9', 'v1.13', 'v1.14.1', 'v1.14.2']\n\n    "

    def version_to_tuple(version):
        version_list = version[1:].split('.', 2)
        if (len(version_list) <= 3):
            [version_list.append(0) for _ in range((3 - len(version_list)))]
        try:
            return tuple((int(version) for version in version_list))
        except ValueError:
            return (0, 0, 0)
    (x_major, x_minor, x_bugfix) = version_to_tuple(x)
    (y_major, y_minor, y_bugfix) = version_to_tuple(y)
    return (cmp(x_major, y_major) or cmp(x_minor, y_minor) or cmp(x_bugfix, y_bugfix))

dataset/ETHPy150Open openxc/openxc-python/fabfile.py compare_versions/original