.. versionadded:: 2017.7.3

    List all available versions of a pip package

    pkg
        The package to check

    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.

    include_alpha
        Include alpha versions in the list

    include_beta
        Include beta versions in the list

    include_rc
        Include release candidates versions in the list

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    index_url
        Base URL of Python Package Index
        .. versionadded:: 2019.2.0

    extra_index_url
        Additional URL of Python Package Index
        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

       salt '*' pip.list_all_versions <package name>

def list_all_versions(pkg,
                      bin_env=None,
                      include_alpha=False,
                      include_beta=False,
                      include_rc=False,
                      user=None,
                      cwd=None,
                      index_url=None,
                      extra_index_url=None):
    '''
    .. versionadded:: 2017.7.3

    List all available versions of a pip package

    pkg
        The package to check

    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.

    include_alpha
        Include alpha versions in the list

    include_beta
        Include beta versions in the list

    include_rc
        Include release candidates versions in the list

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    index_url
        Base URL of Python Package Index
        .. versionadded:: 2019.2.0

    extra_index_url
        Additional URL of Python Package Index
        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

       salt '*' pip.list_all_versions <package name>
    '''
    cmd = _get_pip_bin(bin_env)
    cmd.extend(['install', '{0}==versions'.format(pkg)])

    if index_url:
        if not salt.utils.url.validate(index_url, VALID_PROTOS):
            raise CommandExecutionError(
                '\'{0}\' is not a valid URL'.format(index_url)
            )
        cmd.extend(['--index-url', index_url])

    if extra_index_url:
        if not salt.utils.url.validate(extra_index_url, VALID_PROTOS):
            raise CommandExecutionError(
                '\'{0}\' is not a valid URL'.format(extra_index_url)
            )
        cmd.extend(['--extra-index-url', extra_index_url])

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

    result = __salt__['cmd.run_all'](cmd, **cmd_kwargs)

    filtered = []
    if not include_alpha:
        filtered.append('a')
    if not include_beta:
        filtered.append('b')
    if not include_rc:
        filtered.append('rc')
    if filtered:
        excludes = re.compile(r'^((?!{0}).)*$'.format('|'.join(filtered)))
    else:
        excludes = re.compile(r'')

    versions = []
    for line in result['stdout'].splitlines():
        match = re.search(r'\s*Could not find a version.* \(from versions: (.*)\)', line)
        if match:
            versions = [v for v in match.group(1).split(', ') if v and excludes.match(v)]
            versions.sort(key=pkg_resources.parse_version)
            break
    if not versions:
        return None

    return versions