def list_upgrades(bin_env=None,
                  user=None,
                  cwd=None):
    '''
    Check whether or not an upgrade is available for all packages

    CLI Example:

    .. code-block:: bash

        salt '*' pip.list_upgrades
    '''
    cmd = _get_pip_bin(bin_env)
    cmd.extend(['list', '--outdated'])

    pip_version = version(bin_env)
    # Pip started supporting the ability to output json starting with 9.0.0
    min_version = '9.0'
    if salt.utils.versions.compare(ver1=pip_version,
                                   oper='>=',
                                   ver2=min_version):
        cmd.append('--format=json')

    cmd_kwargs = dict(cwd=cwd, runas=user)
    if bin_env and os.path.isdir(bin_env):
        cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}

    result = __salt__['cmd.run_all'](cmd, **cmd_kwargs)
    if result['retcode']:
        raise CommandExecutionError(result['stderr'], info=result)

    packages = {}
    # Pip started supporting the ability to output json starting with 9.0.0
    # Older versions will have to parse stdout
    if salt.utils.versions.compare(ver1=pip_version, oper='<', ver2='9.0.0'):
        # Pip versions < 8.0.0 had a different output format
        # Sample data:
        # pip (Current: 7.1.2 Latest: 10.0.1 [wheel])
        # psutil (Current: 5.2.2 Latest: 5.4.5 [wheel])
        # pyasn1 (Current: 0.2.3 Latest: 0.4.2 [wheel])
        # pycparser (Current: 2.17 Latest: 2.18 [sdist])
        if salt.utils.versions.compare(ver1=pip_version, oper='<', ver2='8.0.0'):
            logger.debug('pip module: Old output format')
            pat = re.compile(r'(\S*)\s+\(.*Latest:\s+(.*)\)')

        # New output format for version 8.0.0+
        # Sample data:
        # pip (8.0.0) - Latest: 10.0.1 [wheel]
        # psutil (5.2.2) - Latest: 5.4.5 [wheel]
        # pyasn1 (0.2.3) - Latest: 0.4.2 [wheel]
        # pycparser (2.17) - Latest: 2.18 [sdist]
        else:
            logger.debug('pip module: New output format')
            pat = re.compile(r'(\S*)\s+\(.*\)\s+-\s+Latest:\s+(.*)')

        for line in result['stdout'].splitlines():
            match = pat.search(line)
            if match:
                name, version_ = match.groups()
            else:
                logger.error('Can\'t parse line \'%s\'', line)
                continue
            packages[name] = version_

    else:
        logger.debug('pip module: JSON output format')
        try:
            pkgs = salt.utils.json.loads(result['stdout'], strict=False)
        except ValueError:
            raise CommandExecutionError('Invalid JSON', info=result)

        for pkg in pkgs:
            packages[pkg['name']] = '{0} [{1}]'.format(pkg['latest_version'],
                                                       pkg['latest_filetype'])

    return packages
Check whether or not an upgrade is available for all packages

    CLI Example:

    .. code-block:: bash

        salt '*' pip.list_upgrades