from pathlib import Path


def dir_contains(file, directory):
    """Check if 'file' is or is contained by 'directory'."""

    file = Path(file)
    directory = Path(directory)
    while file.parent != file:
        if file == directory:
            return True
        file = file.parent
    return False