Return a list of installed packages either globally or in the specified
    virtualenv

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    .. note::
        If the version of pip available is older than 8.0.3, the list will not
        include the packages ``pip``, ``wheel``, ``setuptools``, or
        ``distribute`` even if they are installed.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.freeze bin_env=/home/code/path/to/virtualenv

def freeze(bin_env=None,
           user=None,
           cwd=None,
           use_vt=False,
           env_vars=None,
           **kwargs):
    '''
    Return a list of installed packages either globally or in the specified
    virtualenv

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    .. note::
        If the version of pip available is older than 8.0.3, the list will not
        include the packages ``pip``, ``wheel``, ``setuptools``, or
        ``distribute`` even if they are installed.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.freeze bin_env=/home/code/path/to/virtualenv
    '''
    cmd = _get_pip_bin(bin_env)
    cmd.append('freeze')

    # Include pip, setuptools, distribute, wheel
    min_version = '8.0.3'
    cur_version = version(bin_env)
    if salt.utils.versions.compare(ver1=cur_version, oper='<', ver2=min_version):
        logger.warning(
            'The version of pip installed is %s, which is older than %s. '
            'The packages pip, wheel, setuptools, and distribute will not be '
            'included in the output of pip.freeze', cur_version, min_version
        )
    else:
        cmd.append('--all')

    cmd_kwargs = dict(runas=user, cwd=cwd, use_vt=use_vt, python_shell=False)
    if kwargs:
        cmd_kwargs.update(**kwargs)
    if bin_env and os.path.isdir(bin_env):
        cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
    if env_vars:
        cmd_kwargs.setdefault('env', {}).update(_format_env_vars(env_vars))
    result = __salt__['cmd.run_all'](cmd, **cmd_kwargs)

    if result['retcode']:
        raise CommandExecutionError(result['stderr'], info=result)

    return result['stdout'].splitlines()