from typing import Set


def select_define(defines: Set[str], family_header: str) -> str:
    """Selects valid define from set of potential defines.

    Looks for the defines in the family header to pick the correct one.

    Args:
        defines: set of defines provided by `parse_product_str`
        family_header: `{family}.h` read into a string

    Returns:
        A single valid define

    Raises:
        ValueError if exactly one define is not found.
    """
    valid_defines = list(
        filter(
            lambda x: f'defined({x})' in family_header or f'defined ({x})' in
            family_header, defines))

    if len(valid_defines) != 1:
        raise ValueError("Unable to select a valid define")

    return valid_defines[0]