from pkg_resources import (
        DistributionNotFound,
        VersionConflict,
        RequirementParseError,
)
import pkg_resources
from pathlib import Path
import warnings


def is_requirements_installed(
    requirements_file: 'Path', show_warning: bool = False
) -> bool:
    """Return True if requirements.txt is installed locally
    :param requirements_file: the requirements.txt file
    :param show_warning: if to show a warning when a dependency is not satisfied
    :return: True of False if not satisfied
    """

    try:
        with requirements_file.open() as requirements:
            pkg_resources.require(requirements)
    except (DistributionNotFound, VersionConflict, RequirementParseError) as ex:
        if show_warning:
            warnings.warn(str(ex), UserWarning)
        return False
    return True