Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sphinx.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. """
  3. celery.contrib.sphinx
  4. =====================
  5. Sphinx documentation plugin
  6. **Usage**
  7. Add the extension to your :file:`docs/conf.py` configuration module:
  8. .. code-block:: python
  9. extensions = (...,
  10. 'celery.contrib.sphinx')
  11. If you would like to change the prefix for tasks in reference documentation
  12. then you can change the ``celery_task_prefix`` configuration value:
  13. .. code-block:: python
  14. celery_task_prefix = '(task)' # < default
  15. With the extension installed `autodoc` will automatically find
  16. task decorated objects and generate the correct (as well as
  17. add a ``(task)`` prefix), and you can also refer to the tasks
  18. using `:task:proj.tasks.add` syntax.
  19. Use ``.. autotask::`` to manually document a task.
  20. """
  21. from __future__ import absolute_import
  22. try:
  23. from inspect import formatargspec, getfullargspec as getargspec
  24. except ImportError: # Py2
  25. from inspect import formatargspec, getargspec # noqa
  26. from sphinx.domains.python import PyModulelevel
  27. from sphinx.ext.autodoc import FunctionDocumenter
  28. from celery.app.task import BaseTask
  29. class TaskDocumenter(FunctionDocumenter):
  30. objtype = 'task'
  31. member_order = 11
  32. @classmethod
  33. def can_document_member(cls, member, membername, isattr, parent):
  34. return isinstance(member, BaseTask) and getattr(member, '__wrapped__')
  35. def format_args(self):
  36. wrapped = getattr(self.object, '__wrapped__')
  37. if wrapped is not None:
  38. argspec = getargspec(wrapped)
  39. fmt = formatargspec(*argspec)
  40. fmt = fmt.replace('\\', '\\\\')
  41. return fmt
  42. return ''
  43. def document_members(self, all_members=False):
  44. pass
  45. class TaskDirective(PyModulelevel):
  46. def get_signature_prefix(self, sig):
  47. return self.env.config.celery_task_prefix
  48. def setup(app):
  49. app.add_autodocumenter(TaskDocumenter)
  50. app.domains['py'].directives['task'] = TaskDirective
  51. app.add_config_value('celery_task_prefix', '(task)', True)