.. versionadded:: 2018.3.0

    Filter list of installed apps from ``freeze`` and return True or False  if
    ``pkgname`` exists in the list of packages installed.

    .. note::
        If the version of pip available is older than 8.0.3, the packages
        wheel, setuptools, and distribute will not be reported by this function
        even if they are installed. Unlike :py:func:`pip.freeze
        <salt.modules.pip.freeze>`, this function always reports the version of
        pip which is installed.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.is_installed salt

def is_installed(pkgname=None,
                 bin_env=None,
                 user=None,
                 cwd=None):
    '''
    .. versionadded:: 2018.3.0

    Filter list of installed apps from ``freeze`` and return True or False  if
    ``pkgname`` exists in the list of packages installed.

    .. note::
        If the version of pip available is older than 8.0.3, the packages
        wheel, setuptools, and distribute will not be reported by this function
        even if they are installed. Unlike :py:func:`pip.freeze
        <salt.modules.pip.freeze>`, this function always reports the version of
        pip which is installed.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.is_installed salt
    '''
    for line in freeze(bin_env=bin_env, user=user, cwd=cwd):
        if line.startswith('-f') or line.startswith('#'):
            # ignore -f line as it contains --find-links directory
            # ignore comment lines
            continue
        elif line.startswith('-e hg+not trust'):
            # ignore hg + not trust problem
            continue
        elif line.startswith('-e'):
            line = line.split('-e ')[1]
            version_, name = line.split('#egg=')
        elif len(line.split('===')) >= 2:
            name = line.split('===')[0]
            version_ = line.split('===')[1]
        elif len(line.split('==')) >= 2:
            name = line.split('==')[0]
            version_ = line.split('==')[1]
        else:
            logger.error('Can\'t parse line \'%s\'', line)
            continue

        if pkgname:
            if pkgname == name.lower():
                return True

    return False