from pathlib import Path


def is_imported(filepath: Path, pkg_name: str) -> bool:
    """checks if a package has been imported in a file
    """

    imported = False
    with open(filepath, 'r') as f:
        content = f.read()
        tokens = content.split()

    check_indexes = []
    for idx, t in enumerate(tokens):
        if pkg_name in t:
            check_indexes.append(idx)


    for idx in check_indexes:
        try:
            assert idx > 0
            assert idx < len(tokens) - 1

            if tokens[idx-1] ==  'import': 
                imported = True
            elif tokens[idx-1] == 'from' and tokens[idx+1] == "import":
                imported = True
        except ValueError:
            pass

    return imported