
    xai                         d Z ddl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	e	      Z G d
 de      Zd Zd Zy)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.

Sphinx 9.0+ Compatibility
-------------------------

Sphinx 9.0 introduced a rewritten autodoc implementation. The Celery
extension requires the legacy class-based autodoc mode to function
correctly. When using Sphinx 9.0 or later, add the following to your
:file:`conf.py`:

.. code-block:: python

    autodoc_use_legacy_class_based = True

The extension will automatically enable this setting if not configured,
but it is recommended to set it explicitly to avoid warnings.
    N)	signature)nodes)
PyFunction)FunctionDocumenter)BaseTaskc                   H     e Zd ZdZdZdZed        Zd ZddZ	 fdZ
 xZS )	TaskDocumenterzDocument task definitions.task   c                 >    t        |t              xr t        |d      S )N__wrapped__
isinstancer   getattr)clsmember
membernameisattrparents        g/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/celery/contrib/sphinx.pycan_document_memberz"TaskDocumenter.can_document_member@   s    &(+N0NN    c                    t        | j                  dd       }|ht        |      }d|j                  v sd|j                  v r6|j	                  t        |j                  j                               dd        }t        |      S y)Nr   selfr      )
parameters )r   objectr   r   replacelistvaluesstr)r   wrappedsigs      r   format_argszTaskDocumenter.format_argsD   sp    $++}d;G$C'5CNN+BkkT#..2G2G2I-J12-NkOs8Or   c                      y N )r   all_memberss     r   document_memberszTaskDocumenter.document_membersM   s    r   c                     t        | j                  dd       }|rt        |d      | j                  k(  ryt        |          S )Nr   
__module__T)r   r   modnamesupercheck_module)r   r#   	__class__s     r   r/   zTaskDocumenter.check_moduleP   s=    
 $++}d;ww5Ew#%%r   )F)__name__r,   __qualname____doc__objtypemember_orderclassmethodr   r%   r*   r/   __classcell__)r0   s   @r   r	   r	   :   s8    $GLO O& &r   r	   c                       e Zd ZdZd Zy)TaskDirectivezSphinx task directive.c                 j    t        j                  | j                  j                  j                        gS r'   )r   Textenvconfigcelery_task_prefix)r   r$   s     r   get_signature_prefixz"TaskDirective.get_signature_prefix^   s"    

488??==>??r   N)r1   r,   r2   r3   r?   r(   r   r   r9   r9   [   s     @r   r9   c                 B    t        |t              rt        |d      r|ryy)z&Handler for autodoc-skip-member event.r   FNr   )appwhatnameobjskipoptionss         r   autodoc_skip_member_handlerrG   b   s      #x WS-%@r   c                    ddl }| j                  d       t        d |j                  j	                  d      dd D              }|dk\  rDt        | j                  dd	      s-t        j                  d
t        d       d| j                  _
        | j                  t               | j                  ddt               | j                  ddd       | j!                  dt"               ddiS )zSetup Sphinx extension.r   Nzsphinx.ext.autodocc              3   2   K   | ]  }t        |        y wr'   )int).0xs     r   	<genexpr>zsetup.<locals>.<genexpr>w   s     Ma3q6Ms   .   )	   r   autodoc_use_legacy_class_basedFzSphinx 9.0+ detected. celery.contrib.sphinx requires 'autodoc_use_legacy_class_based = True' in conf.py. Enabling it automatically.)
stacklevelTpyr
   r>   z(task)zautodoc-skip-memberparallel_read_safe)sphinxsetup_extensiontuple__version__splitr   r=   warningswarnUserWarningrQ   add_autodocumenterr	   add_directive_to_domainr9   add_config_valueconnectrG   )rA   rU   sphinx_versions      r   setuprb   o   s    ,- M6+=+=+C+CC+H!+LMMNszz#CUKMM-  9=CJJ5>*fm<-x>KK%'BC 	d r   )r3   rZ   inspectr   docutilsr   sphinx.domains.pythonr   sphinx.ext.autodocr   celery.app.taskr   r	   r9   rG   rb   r(   r   r   <module>rh      sE   .^    , 1 $&' &B@J @
r   