
    Lg                        d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ erd dlmZ  ed	      Z e
d
      Z G d d      Z ed      d        Z e
dd      Z G d de	e         Zy)    )annotations)Callable)	lru_cachewraps)TYPE_CHECKINGGenericTypeVar)config)importlib_metadata)funcname)	ParamSpecBackendFuncParamsBackendFuncReturnc                  0    e Zd ZdZed        Zed        Zy)DaskBackendEntrypointa  Base Collection-Backend Entrypoint Class

    Most methods in this class correspond to collection-creation
    for a specific library backend. Once a collection is created,
    the existing data will be used to dispatch compute operations
    within individual tasks. The backend is responsible for
    ensuring that these data-directed dispatch functions are
    registered when ``__init__`` is called.
    c                    t         )z7Return a dispatch function to move data to this backendNotImplementedError)clss    -lib/python3.12/site-packages/dask/backends.pyto_backend_dispatchz)DaskBackendEntrypoint.to_backend_dispatch   
     "!    c                    t         )z)Create a new collection with this backendr   )datas    r   
to_backendz DaskBackendEntrypoint.to_backend"   r   r   N)__name__
__module____qualname____doc__classmethodr   staticmethodr    r   r   r   r      s/     " " " "r   r      )maxsizec                j    t        j                  |       D ci c]  }|j                  | c}S c c}w )N)group)r   entry_pointsname)entry_point_nameeps     r   detect_entrypointsr,   (   s:     1==DTUUU  s   0BackendEntrypointType)boundc                      e Zd ZU dZded<   ded<   ded<   ded<   ded	<   ded
<   	 	 d	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZedd       Z	e	j                  dd       Z		 d	 	 	 	 	 ddZddZy)CreationDispatchz9Simple backend dispatch for collection-creation functionsz dict[str, BackendEntrypointType]_lookupstr_module_name_config_field_defaulttype[BackendEntrypointType]_entrypoint_class_entrypoint_rootNc                r    i | _         || _        | d| _        || _        || _        || _        |r|| _        y y )Nz.backend)r1   r3   r4   r5   r7   r8   r   )selfmodule_namedefaultentrypoint_classr)   entrypoint_roots         r   __init__zCreationDispatch.__init__?   sH     ' +}H5!1 / DM r   c                    t        || j                        s$t        d| j                   dt        |             || j                  |<   |S )z:Register a target class for a specific array-backend labelz$This CreationDispatch only supports z registration. Got )
isinstancer7   
ValueErrortyper1   )r:   r)   backends      r   register_backendz!CreationDispatch.register_backendP   sX     '4#9#9:6))* +G}o' 
 %Tr   c                   	 | j                   |   }|S # t        $ rV t        | j                   d| j                   d      }||v r*| j                  | ||   j                                      cY S Y nw xY wt        d|       )z%Return the desired backend entrypoint.z	.backendsz#No backend dispatch registered for )r1   KeyErrorr,   r8   r3   rE   loadrB   )r:   rD   implentrypointss       r   dispatchzCreationDispatch.dispatch]   s    
	<<(D K  	U,(()4+<+<*=YGK +%,,W6Qk'6J6O6O6Q6STT &	U >wiHIIs    AA21A2c                r    t        j                  | j                  | j                        xs | j                  S )z%Return the desired collection backend)r
   getr4   r5   )r:   s    r   rD   zCreationDispatch.backendl   s(     zz$,,dmm<MMr   c                4    t        d| j                   d      )Nz#Set the backend by configuring the z option)RuntimeErrorr4   )r:   values     r   rD   zCreationDispatch.backendq   s"    1$2D2D1EWM
 	
r   c                $     	 	 	 	 d fd}|S )zRegister dispatchable functionc                    xs | j                   j                        }|j                  |        t        |       fd       }|_         |S )Nc            	         t              }	  || i |S # t        $ rE}	  t        |      dt        |       dj                   d|       }||# t
        $ r |w xY wd }~ww xY w)Nz$An error occurred while calling the z method registered to the z backend.
Original Message: )getattr	ExceptionrC   r   rD   	TypeError)argskwargsfunceexcdispatch_namer:   s        r   wrapperzECreationDispatch.register_inplace.<locals>.decorator.<locals>.wrapper   s    t]3)000  
)	)%d1gB8D>BR S88<~ F1125 "q( %   
)s&    	A%-AA AA  A%)r   rL   __setattr__r   )fn
dispatcherr^   r]   rD   r)   r:   s      @r   	decoratorz4CreationDispatch.register_inplace.<locals>.decorator   sV     !/BKKMw/J""="52Y) )   -GNr   )r`   .Callable[BackendFuncParams, BackendFuncReturn]returnrc   r#   )r:   rD   r)   rb   s   ``` r   register_inplacez!CreationDispatch.register_inplacew   s     	>	;	6 r   c                P    | j                  | j                        }t        ||      S )zJ
        Return the appropriate attribute for the current backend
        )rL   rD   rU   )r:   itemrD   s      r   __getattr__zCreationDispatch.__getattr__   s#     ---w%%r   )Ndask)
r;   r2   r<   r2   r=   r6   r)   
str | Noner>   r2   )r)   r2   rD   r-   rd   r-   )rD   r2   )rd   r2   )rQ   r2   )N)rD   r2   r)   rj   rd   zjCallable[[Callable[BackendFuncParams, BackendFuncReturn]], Callable[BackendFuncParams, BackendFuncReturn]])rg   r2   )r   r   r   r    __annotations__r?   rE   rL   propertyrD   setterre   rh   r#   r   r   r0   r0   5   s    C--M22  %!! ! 6	!
 ! !""7	J N N ^^
 
  %% %
	%N&r   r0   N)
__future__r   collections.abcr   	functoolsr   r   typingr   r   r	   ri   r
   dask._compatibilityr   
dask.utilsr   typing_extensionsr   r   r   r   r,   r-   r0   r#   r   r   <module>ru      s    " $ & 2 2  2 +!"56 34" ", 1   
! n&w45 n&r   