U
    .e?                     @   st   d Z ddlmZ ddl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.
    )	signature)nodes)
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-f4liivr4/celery/contrib/sphinx.pycan_document_member0   s    z"TaskDocumenter.can_document_memberc                 C   s\   t | jdd }|d k	rXt|}d|jks2d|jkrP|jt|j dd  d}t|S dS )Nr
   selfr      )
parameters )r   objectr   r   replacelistvaluesstr)r   wrappedsigr   r   r   format_args4   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%   @   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   t | jjjgS r    )r   Textenvconfigcelery_task_prefix)r   r   r   r   r   get_signature_prefixN   s    z"TaskDirective.get_signature_prefixN)r(   r"   r)   r*   r2   r   r   r   r   r-   K   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_handlerR   s    r9   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   r1   z(task)Tzautodoc-skip-memberZparallel_read_safe)Zsetup_extensionZadd_autodocumenterr   Zadd_directive_to_domainr-   Zadd_config_valueconnectr9   )r3   r   r   r   setup_   s    

 r<   N)r*   inspectr   Zdocutilsr   Zsphinx.domains.pythonr   Zsphinx.ext.autodocr   Zcelery.app.taskr   r   r-   r9   r<   r   r   r   r   <module>   s    !