
    Ki                    J   d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	m
Z
mZmZ erddlmZ dd	lmZ dd
lmZ  G d de	d         Zd!dZ G d de	d         Zd"dZ G d de	d         Zd#dZ G d de	e         Zd$dZ G d de	e         Zd%d&dZ G d de	d         Zd'd Zy)(zMContextual dependencies for accessing current Docket, Worker, Execution, etc.    )annotationsN)TYPE_CHECKINGAnycast   )
Dependencycurrent_docketcurrent_executioncurrent_worker   )Docket)	Execution)Workerc                      e Zd ZddZy)_CurrentWorkerc                2   K   t        j                         S wN)r   getselfs    k/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docket/dependencies/_contextual.py
__aenter__z_CurrentWorker.__aenter__        !!##   Nreturnr   __name__
__module____qualname__r        r   r   r          $r"   r   r   c                 *    t        dt                     S )zA dependency to access the current Worker.

    Example:

    ```python
    @task
    async def my_task(worker: Worker = CurrentWorker()) -> None:
        assert isinstance(worker, Worker)
    ```
    r   )r   r   r!   r"   r   CurrentWorkerr%           .*++r"   c                      e Zd ZddZy)_CurrentDocketc                2   K   t        j                         S wr   )r	   r   r   s    r   r   z_CurrentDocket.__aenter__$   r   r   Nr   r   r   r!   r"   r   r(   r(   #   r#   r"   r(   r   c                 *    t        dt                     S )zA dependency to access the current Docket.

    Example:

    ```python
    @task
    async def my_task(docket: Docket = CurrentDocket()) -> None:
        assert isinstance(docket, Docket)
    ```
    r   )r   r(   r!   r"   r   CurrentDocketr,   (   r&   r"   c                      e Zd ZddZy)_CurrentExecutionc                2   K   t        j                         S wr   )r
   r   r   s    r   r   z_CurrentExecution.__aenter__7   s      $$&&r   Nr   r   r   r!   r"   r   r.   r.   6   s    'r"   r.   r   c                 *    t        dt                     S )zA dependency to access the current Execution.

    Example:

    ```python
    @task
    async def my_task(execution: Execution = CurrentExecution()) -> None:
        assert isinstance(execution, Execution)
    ```
    r   )r   r.   r!   r"   r   CurrentExecutionr2   ;   s     .011r"   c                      e Zd ZddZy)_TaskKeyc                F   K   t        j                         j                  S wr   )r
   r   keyr   s    r   r   z_TaskKey.__aenter__J   s      $$&***s   !Nr   strr   r!   r"   r   r4   r4   I   s    +r"   r4   c                 2    t        t        t                     S )zA dependency to access the key of the currently executing task.

    Example:

    ```python
    @task
    async def my_task(key: str = TaskKey()) -> None:
        assert isinstance(key, str)
    ```
    )r   r8   r4   r!   r"   r   TaskKeyr:   N   s     XZ  r"   c                  4    e Zd ZU ded<   ded<   dd	dZd
dZy)_TaskArgument
str | None	parameterbooloptionalNc                     || _         || _        y r   r>   r@   )r   r>   r@   s      r   __init__z_TaskArgument.__init__`   s    " r"   c                   K   | j                   J t        j                         }	 |j                  | j                         S # t        $ r | j
                  rY y  w xY wwr   )r>   r
   r   get_argumentKeyErrorr@   )r   	executions     r   r   z_TaskArgument.__aenter__d   sY     ~~)))%))+		))$..99 	}}	s(   #AA  AAAAANF)r>   r=   r@   r?   r   None)r   r   )r   r   r    __annotations__rC   r   r!   r"   r   r<   r<   \   s    N!r"   r<   c                6    t        t        t        | |            S )a   A dependency to access a argument of the currently executing task.  This is
    often useful in dependency functions so they can access the arguments of the
    task they are injected into.

    Example:

    ```python
    async def customer_name(customer_id: int = TaskArgument()) -> str:
        ...look up the customer's name by ID...
        return "John Doe"

    @task
    async def greet_customer(customer_id: int, name: str = Depends(customer_name)) -> None:
        print(f"Hello, {name}!")
    ```
    )r   r   r<   rB   s     r   TaskArgumentrL   o   s    " ]9h788r"   c                      e Zd ZddZy)_TaskLoggerc                J  K   t        j                         }t        j                  d|j                         }t        j
                  |i t        j                         j                         t        j                         j                         |j                               S w)Nzdocket.task.)
r
   r   logging	getLoggerfunction_nameLoggerAdapterr	   labelsr   specific_labels)r   rG   loggers      r   r   z_TaskLogger.__aenter__   s     %))+	""\)2I2I1J#KL$$ $$&--/ $$&--/ ++-
 	
s   B!B#Nr   %logging.LoggerAdapter[logging.Logger]r   r!   r"   r   rN   rN      s    

r"   rN   rX   c                 *    t        dt                     S )a  A dependency to access a logger for the currently executing task.  The logger
    will automatically inject contextual information such as the worker and docket
    name, the task key, and the current execution attempt number.

    Example:

    ```python
    @task
    async def my_task(logger: "LoggerAdapter[Logger]" = TaskLogger()) -> None:
        logger.info("Hello, world!")
    ```
    rX   )r   rN   r!   r"   r   
TaskLoggerrZ      s     7GGr"   r   r*   r0   r7   rH   )r>   r=   r@   r?   r   r   rW   ) __doc__
__future__r   rP   typingr   r   r   _baser   r	   r
   r   docketr   rG   r   workerr   r   r%   r(   r,   r.   r2   r8   r4   r:   r<   rL   rN   rZ   r!   r"   r   <module>ra      s    S "  + + P P%$Z) $
,$Z) $
,'
;/ '
2+z# +
!JsO &9(
*DE 
Hr"   