o
    wvXj<  ã                   @   s¤   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 z
ddl
mZmZ W n ey7   ddl
mZmZ Y nw 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.
é    )Úabsolute_importÚunicode_literals)Ú
PyFunction)ÚFunctionDocumenter)ÚBaseTask)ÚformatargspecÚgetfullargspec)r   Ú
getargspecc                       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ÚmemberÚ
membernameÚisattrÚparent© r   úR/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/contrib/sphinx.pyÚcan_document_member5   s   z"TaskDocumenter.can_document_memberc                 C   s\   t | jdd ƒ}|d ur,t|ƒ}|d r |d d dv r |d d= t|Ž }| dd¡}|S dS )Nr   r   )r   Úselfú\z\\Ú )r   Úobjectr   r   Úreplace)r   ÚwrappedÚargspecÚfmtr   r   r   Úformat_args9   s   
zTaskDocumenter.format_argsFc                 C   s   d S ©Nr   )r   Úall_membersr   r   r   Údocument_membersD   s   zTaskDocumenter.document_membersc                    s4   t | jdd ƒ}|rt |dƒ| jkrdS tt| ƒ ¡ S )Nr   Ú
__module__T)r   r   ÚmodnameÚsuperr
   Úcheck_module)r   r   ©Ú	__class__r   r   r(   G   s   zTaskDocumenter.check_module)F)Ú__name__r%   Ú__qualname__Ú__doc__ÚobjtypeÚ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_prefixU   s   
z"TaskDirective.get_signature_prefixN)r+   r%   r,   r-   r7   r   r   r   r   r2   R   s    r2   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_handlerY   s   r>   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   r5   z(task)Tzautodoc-skip-memberÚparallel_read_safe)Úsetup_extensionÚadd_autodocumenterr
   Úadd_directive_to_domainr2   Úadd_config_valueÚconnectr>   )r8   r   r   r   Úsetupf   s   

ÿrF   N)r-   Ú
__future__r   r   Úsphinx.domains.pythonr   Úsphinx.ext.autodocr   Úcelery.app.taskr   Úinspectr   r   ÚImportErrorr	   r
   r2   r>   rF   r   r   r   r   Ú<module>   s    ÿ#