Get tuple version from installed package information for easy handling.

    It will return :attr:`default` value when the named package is not
    installed.

    Parameters
    -----------
    name : string
        An application name used to install via setuptools.
    default : tuple
        A default returning value used when the named application is not
        installed yet
    allow_ambiguous : boolean
        ``True`` for allowing ambiguous version information.

    Returns
    --------
    string
        A version tuple

    Examples
    --------
    >>> v = get_tuple_version('app_version', allow_ambiguous=True)
    >>> len(v) >= 3
    True
    >>> isinstance(v[0], int)
    True
    >>> isinstance(v[1], int)
    True
    >>> isinstance(v[2], int)
    True
    >>> get_tuple_version('distribution_which_is_not_installed')
    (0, 0, 0)

def get_tuple_version(name,
                      default=DEFAULT_TUPLE_NOT_FOUND,
                      allow_ambiguous=True):
    """
    Get tuple version from installed package information for easy handling.

    It will return :attr:`default` value when the named package is not
    installed.

    Parameters
    -----------
    name : string
        An application name used to install via setuptools.
    default : tuple
        A default returning value used when the named application is not
        installed yet
    allow_ambiguous : boolean
        ``True`` for allowing ambiguous version information.

    Returns
    --------
    string
        A version tuple

    Examples
    --------
    >>> v = get_tuple_version('app_version', allow_ambiguous=True)
    >>> len(v) >= 3
    True
    >>> isinstance(v[0], int)
    True
    >>> isinstance(v[1], int)
    True
    >>> isinstance(v[2], int)
    True
    >>> get_tuple_version('distribution_which_is_not_installed')
    (0, 0, 0)
    """
    def _prefer_int(x):
        try:
            return int(x)
        except ValueError:
            return x
    version = get_string_version(name, default=default,
                                 allow_ambiguous=allow_ambiguous)
    # convert string version to tuple version
    # prefer integer for easy handling
    if isinstance(version, tuple):
        # not found
        return version
    return tuple(map(_prefer_int, version.split('.')))