Пример #1
0
def test_api_lookup():
    try:
        strurl = misc.find_api_page('astropy.utils.misc',
                                    'dev',
                                    False,
                                    timeout=3)
        objurl = misc.find_api_page(misc, 'dev', False, timeout=3)
    except socket.timeout:
        if os.environ.get('CI', False):
            pytest.xfail('Timed out in CI')
        else:
            raise

    assert strurl == objurl
    assert strurl == 'http://devdocs.astropy.org/utils/index.html#module-astropy.utils.misc'  # noqa

    # Try a non-dev version
    objurl = misc.find_api_page(misc, 'v3.2.1', False, timeout=3)
    assert objurl == 'https://docs.astropy.org/en/v3.2.1/utils/index.html#module-astropy.utils.misc'  # noqa
Пример #2
0
def test_api_lookup():
    strurl = misc.find_api_page('astropy.utils.misc', 'dev', False, timeout=3)
    objurl = misc.find_api_page(misc, 'dev', False, timeout=3)

    assert strurl == objurl
    assert strurl == 'http://devdocs.astropy.org/utils/index.html#module-astropy.utils.misc'
Пример #3
0
def online_help(query: T.Union[None, str, T.Any] = None, version=__version__):
    """Search the online documentation for the given query.

    Opens the results in the default web browser.
    Requires an active internet connection.

    Parameters
    ----------
    query : str, object, optional
        The search query for `RTD <https://utislipy.readthedocs.io>`_.
        None (default) or "" is an empty search.
        If an object, uses :func:`~astropy.utils.misc.find_api_page`
        to find the correct API page.

    Examples
    --------
    To do a specific search of `utilipy`'s docs, use the ``online_help``
    function. If you don't have a specific query, that's fine too,
    `utilipy` will open the general search page.

    As an example, here we query RTD for the documentation on `LogFile`.

        >>> import utilipy
        >>> utilipy.online_help(query="LogFile") # doctest: +SKIP

    The same can be accomplished with the general `help` function.

        >>> import utilipy
        >>> utilipy.help(query="LogFile", online=True) # doctest: +SKIP

    See Also
    --------
    :func:`~utilipy.help`

    """
    # first get version to search
    if "dev" in version:
        version = "latest"
    else:
        version = version if version.startswith("v") else "v" + version

    # look up objects
    if not isinstance(query, str) and query is not None:
        if version == "latest":
            version = None
        return find_api_page(query, version=version, openinbrowser=True)

    # else:

    from urllib.parse import urlencode
    import webbrowser

    # process the query
    if query is None:  # empty query, empty search
        query = ""
    else:  # encode the query
        query: str = urlencode({"q": query})

    url = f"https://utilipy.readthedocs.io/en/{version}/search.html?{query}"

    webbrowser.open(url)
Пример #4
0
def test_api_lookup():
    strurl = misc.find_api_page('astropy.utils.misc', 'dev', False, timeout=3)
    objurl = misc.find_api_page(misc, 'dev', False, timeout=3)

    assert strurl == objurl
    assert strurl == 'http://devdocs.astropy.org/utils/index.html#module-astropy.utils.misc'