import re


def _mk_version_tuple(version):
    """Create a version tuple as required by a version info file.

    Note: non-numeric parts of the version are stripped entirely and
          empty numbers are replaced by zero's (1..1 -> 1.0.1)

    Args:
        version: a version string, e.g. '1', '1.2', '1.2.3', '1.2.dev3'

    Returns:
        tuple with a cleaned up 3 digit version and a string with a
        4 digit version 'tuple', e.g.:
            '1'        -> ('1.0.0', '(1, 0, 0, 0)')
            '1.2'      -> ('1.2.0', '(1, 2, 0, 0)')
            '1.2.3'    -> ('1.2.3', '(1, 2, 3, 0)')
            '1.2.dev3' -> ('1.2.3', '(1, 2, 3, 0)')
            '1.2.3.4'  -> ('1.2.3', '(1, 2, 3, 4)')
            '1..3.4'   -> ('1.0.3', '(1, 0, 3, 4)')
    """
    version = [re.sub("[^0-9]", "", n) for n in version.split(".")[:4]]
    version = [int(n) if n else 0 for n in version]
    if len(version) < 4:
        version.extend([0] * (4 - len(version)))
    version_text = ".".join([str(n) for n in version[:3]])
    version_tuple = ", ".join([str(n) for n in version])
    return version_text, f"({version_tuple})"