def get_plugin_info(plugin):
    """
    Fetch information about the given package on PyPI and return it as a dict.
    If the package cannot be found on PyPI, :exc:`NameError` will be raised.
    """
    url = 'https://pypi.python.org/pypi/{}/json'.format(plugin)

    try:
        resp = request.urlopen(url)
    except HTTPError as e:
        if e.code == 404:
            raise NameError("Plugin {} could not be found.".format(plugin))
        else:
            raise ValueError(
                "Checking plugin status on {} returned HTTP code {}".format(
                    url, resp.getcode()
                )
            )

    try:
        json_resp = json.loads(resp.read().decode())
    # Catch ValueError instead of JSONDecodeError which is only available in
    # Python 3.5+
    except ValueError:
        raise ValueError(
            "Could not decode JSON info for plugin at {}".format(url)
        )

    return json_resp['info']
Fetch information about the given package on PyPI and return it as a dict.
    If the package cannot be found on PyPI, :exc:`NameError` will be raised.