Browse Source

Allow automatically documenting task decorated objects using Sphinx (e.g. with automodule directive) (#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.
Leo Singer 7 years ago
parent
commit
04f29ff725
1 changed files with 15 additions and 4 deletions
  1. 15 4
      celery/contrib/sphinx.py

+ 15 - 4
celery/contrib/sphinx.py

@@ -22,11 +22,12 @@ then you can change the ``celery_task_prefix`` configuration value:
     celery_task_prefix = '(task)'  # < default
 
 With the extension installed `autodoc` will automatically find
-task decorated objects and generate the correct (as well as
-add a ``(task)`` prefix), and you can also refer to the tasks
-using `:task:proj.tasks.add` syntax.
+task decorated objects (e.g. when using the automodule directive)
+and generate the correct (as well as add a ``(task)`` prefix),
+and you can also refer to the tasks using `:task:proj.tasks.add`
+syntax.
 
-Use ``.. autotask::`` to manually document a task.
+Use ``.. autotask::`` to alternatively manually document a task.
 """
 from __future__ import absolute_import, unicode_literals
 
@@ -64,6 +65,16 @@ class TaskDocumenter(FunctionDocumenter):
     def document_members(self, all_members=False):
         pass
 
+    def check_module(self):
+        # Normally checks if *self.object* is really defined in the module
+        # given by *self.modname*. But since functions decorated with the @task
+        # decorator are instances living in the celery.local module we're
+        # checking for that and simply agree to document those then.
+        modname = self.get_attr(self.object, '__module__', None)
+        if modname and modname == 'celery.local':
+            return True
+        return super(TaskDocumenter, self).check_module()
+
 
 class TaskDirective(PyModulelevel):
     """Sphinx task directive."""