U
    ‰dR  ã                   @   sl   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 G dd„ deƒZ
G dd	„ d	eƒZd
d„ Zdd„ ZdS )a]  Sphinx documentation plugin used to document tasks.

Introduction
============

Usage
-----

The Celery extension for Sphinx requires Sphinx 2.0 or later.

Add the extension to your :file:`docs/conf.py` configuration module:

.. code-block:: python

    extensions = (...,
                  'celery.contrib.sphinx')

If you'd like to change the prefix for tasks in reference documentation
then you can change the ``celery_task_prefix`` configuration value:

.. code-block:: python

    celery_task_prefix = '(task)'  # < default

With the extension installed `autodoc` will automatically find
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 alternatively manually document a task.
é    )ÚformatargspecÚgetfullargspec)Ú
PyFunction)ÚFunctionDocumenter)ÚBaseTaskc                       sF   e Zd ZdZdZdZedd„ ƒZdd„ Zdd	d
„Z	‡ fdd„Z
‡  ZS )ÚTaskDocumenterzDocument task definitions.Útaské   c                 C   s   t |tƒot|dƒS )NÚ__wrapped__©Ú
isinstancer   Úgetattr)ÚclsÚmemberZ
membernameZisattrÚparent© r   ú9/tmp/pip-unpacked-wheel-mu1yl971/celery/contrib/sphinx.pyÚcan_document_member/   s    z"TaskDocumenter.can_document_memberc                 C   s\   t | jdd ƒ}|d k	rXt|ƒ}|d r@|d d dkr@|d d= t|Ž }| dd¡}|S dS )Nr
   r   )r   Úselfú\z\\Ú )r   Úobjectr   r   Úreplace)r   ÚwrappedZargspecÚfmtr   r   r   Úformat_args3   s    
zTaskDocumenter.format_argsFc                 C   s   d S ©Nr   )r   Zall_membersr   r   r   Údocument_members>   s    zTaskDocumenter.document_membersc                    s0   t | jdd ƒ}|r&t |dƒ| jkr&dS tƒ  ¡ S )Nr
   Ú
__module__T)r   r   ÚmodnameÚsuperÚcheck_module)r   r   ©Ú	__class__r   r   r!   A   s    zTaskDocumenter.check_module)F)Ú__name__r   Ú__qualname__Ú__doc__ZobjtypeZmember_orderÚclassmethodr   r   r   r!   Ú__classcell__r   r   r"   r   r   )   s   

r   c                   @   s   e Zd ZdZdd„ ZdS )ÚTaskDirectivezSphinx task directive.c                 C   s
   | j jjS r   )ÚenvÚconfigÚcelery_task_prefix)r   Úsigr   r   r   Úget_signature_prefixO   s    z"TaskDirective.get_signature_prefixN)r$   r   r%   r&   r.   r   r   r   r   r)   L   s   r)   c                 C   s    t |tƒrt|dƒr|rdS dS )z&Handler for autodoc-skip-member event.r
   FNr   )ÚappÚwhatÚnameÚobjÚskipÚoptionsr   r   r   Úautodoc_skip_member_handlerS   s    r5   c                 C   sD   |   d¡ |  t¡ |  ddt¡ |  ddd¡ |  dt¡ ddiS )	zSetup Sphinx extension.zsphinx.ext.autodocÚpyr   r,   z(task)Tzautodoc-skip-memberZparallel_read_safe)Zsetup_extensionZadd_autodocumenterr   Zadd_directive_to_domainr)   Zadd_config_valueÚconnectr5   )r/   r   r   r   Úsetup`   s    

 ÿr8   N)r&   Úinspectr   r   Zsphinx.domains.pythonr   Zsphinx.ext.autodocr   Zcelery.app.taskr   r   r)   r5   r8   r   r   r   r   Ú<module>   s    #