sphinx-doc / sphinx-autobuild

Watch a Sphinx directory and rebuild the documentation when a change is detected. Also includes a hot-reload web server.
MIT License
523 stars 75 forks source link

Notes and warning render a new line #144

Closed michael-berk closed 5 months ago

michael-berk commented 5 months ago

Describe the bug

context When I write the below docstring...

def example():
    """
    This is an example.

    :param metadata: Custom metadata dictionary.

        .. Note:: Experimental: This parameter may change or be removed in a future
                                 release without warning.
    :param another_param: another_param
    """

    pass

expectation I expected the docstring definition to render on the same line, as shown below

This is an example.

Parameters
     metadata – Custom metadata dictionary.

        Note
            Experimental: This parameter may change or be removed in a future release without warning.

    another_param – another_param

bug But instead the docstring definition starts on a new line. In the rendered html, there is an additional <p> - one for the definition and another for the note.

This is an example.

Parameters
     metadata – 
     Custom metadata dictionary.

        Note
            Experimental: This parameter may change or be removed in a future release without warning.

    another_param – another_param

problem This is a problem for people using sphinx-autobuild for the following argument in-line use cases (probably not a complete list): code blocks, warnings, bullet lists, notes. For instance, this is an issue throughout the MLflow repo.

Also note that this is issue is not observed for google-style docstrings.

def example_google():
    """
    This is an example.

    Args:
        metadata: Custom metadata dictionary.
            .. Note:: Experimental: This parameter may change or be removed in a future
                                 release without warning.

        another_param: another_param
    """

    pass
image

Reproduce the bug

1 - Install

pip install sphinx-autobuild==2021.3.14

2 - Code

docs/conf.py

import sys
import os

sys.path.insert(0, os.path.abspath('..'))

extensions = [
    'sphinx.ext.autodoc',
]

docs/index.rst

.. toctree::
   :maxdepth: 2

.. automodule:: my_module.repro
   :members:

my_module/repro.py

def example():
    """
    This is an example.

    :param metadata: Custom metadata dictionary.

        .. Note:: Experimental: This parameter may change or be removed in a future
                                 release without warning.
    :param another_param: another_param
    """

    pass

def example_google():
    """
    This is an example.

    Args:
        metadata: Custom metadata dictionary.
            .. Note:: Experimental: This parameter may change or be removed in a future
                                 release without warning.

        another_param: another_param
    """

    pass

3 - Build

sphinx-autobuild -b html docs rendered/

List your environment

Python 3.9.13 sphinx-autobuild==2023.3.14

welcome[bot] commented 5 months ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

pradyunsg commented 5 months ago

As far as I can tell, this is not related to sphinx-autobuild and rather with how Sphinx is parsing the docstring and how it is renderin.

The rendering difference is due to how the HTML theme being used presents parameters formatted appropriately for Sphinx to parse them appropriately. You need to enable napolean to get support for Google style documentation, otherwise it is rendered as a bunch of text paragraphs.