Skip to content

Commit 04f29ff

Browse files
lpsingerOmer Katz
authored andcommitted
Allow automatically documenting task decorated objects using Sphinx (e.g. with automodule directive) (celery#4422)
* Allow automatically documenting task decorated objects using Sphinx (e.g. with automodule directive). * Fix docstyle error Fix this error message: D204: 1 blank line required after class docstring (found 0) * Fix docstyle error This docstring is more of a comment anyway.
1 parent f132d3b commit 04f29ff

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

celery/contrib/sphinx.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
celery_task_prefix = '(task)' # < default
2323
2424
With the extension installed `autodoc` will automatically find
25-
task decorated objects and generate the correct (as well as
26-
add a ``(task)`` prefix), and you can also refer to the tasks
27-
using `:task:proj.tasks.add` syntax.
25+
task decorated objects (e.g. when using the automodule directive)
26+
and generate the correct (as well as add a ``(task)`` prefix),
27+
and you can also refer to the tasks using `:task:proj.tasks.add`
28+
syntax.
2829
29-
Use ``.. autotask::`` to manually document a task.
30+
Use ``.. autotask::`` to alternatively manually document a task.
3031
"""
3132
from __future__ import absolute_import, unicode_literals
3233

@@ -64,6 +65,16 @@ def format_args(self):
6465
def document_members(self, all_members=False):
6566
pass
6667

68+
def check_module(self):
69+
# Normally checks if *self.object* is really defined in the module
70+
# given by *self.modname*. But since functions decorated with the @task
71+
# decorator are instances living in the celery.local module we're
72+
# checking for that and simply agree to document those then.
73+
modname = self.get_attr(self.object, '__module__', None)
74+
if modname and modname == 'celery.local':
75+
return True
76+
return super(TaskDocumenter, self).check_module()
77+
6778

6879
class TaskDirective(PyModulelevel):
6980
"""Sphinx task directive."""

0 commit comments

Comments
 (0)