3
votes

I'm trying to run Sphinx to document the following Celery task, but am getting an empty document upon generating the Sphinx docs:

@celery.task(name='taskname')
def taskname(data):
    """
    Some documentation

    """
    ...

...whereas the following gets documented fine:

def non_decorated_function(data):
    """
    Some documentation

    """
    ...

I understand that the function signature gets mangled by the celery task decorator, but I thought that the following in conf.py was supposed to fix that:

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

My .rst file looks like this:

.. automodule:: tasks
    :members:
    :undoc-members:
    :show-inheritance:

Using autotask does work, but I was hoping to get this working with automodule, as I'm adding this to a significant codebase:

.. automodule:: tasks
    :members:
    :undoc-members:
    :show-inheritance:
.. autotask:: tasks.taskname

Is there any way to fix the celery tasks decorator to be supported by Sphinx documentation?

1
You need new line turn """Some documentation""" to """Some documentation{enter key here}""" - Kobi K
This happens regardless of newline state; sorry about the confusion! - Shookit
Are you sure? pay attention at your edit it's not the right format. """description{enter}""" - Kobi K
autotask is the official way to do it see here - Kobi K
@KobiK That's not what the documentation says. "With the extension installed autodoc will automatically find task decorated objects..." and "Use .. autotask:: to manually document a task." The automatic part, which looks to be officially supported, does not work. Only the manual part works. - kitti

1 Answers

2
votes

Check the official documentation here

Looks like you need to 'celery.contrib.sphinx' within your docs/conf.py file.