from typing import Tuple
import re
import fnmatch


def compile_patterns(patterns: Tuple[str, ...], flags=re.IGNORECASE, use_regex=False):
    """Compile regular expression (or glob) patterns with `re.compile`."""
    if use_regex:
        return re.compile("|".join(patterns), flags=flags)

    return re.compile(
        "|".join(fnmatch.translate(pattern) for pattern in patterns),
        flags=flags,
    )