import glob
import re


def _find_cpt_base(cpt_base):
    """
    Find checkpoint file base name in current directory

    :param str cpt_base: Start of checkpoint file name that ends with a
        number of one to three digits followed by '.cpt'
    :return: The base name of the checkpoint files (everything but the number
        and ".cpt")
    :rtype: str
    """
    possible_matches = glob.glob(cpt_base + "*.cpt")
    for f_name in possible_matches:
        match = re.match(r"({}.*?)\d{}\.cpt".format(cpt_base, "{1,3}"), f_name)
        if match:
            return match.group(1)
    raise ValueError(
        "No checkpoint file name found based on the base " "name {}.".format(cpt_base)
    )