
    >ieH                    $   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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dS )    )annotations)Callable)	lru_cachewraps)TYPE_CHECKINGGenericTypeVarN)config)funcname)	ParamSpecBackendFuncParamsBackendFuncReturnc                  >    e Zd ZdZed             Zed             ZdS )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.11/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      sT          " " [" " " \" " "r   r      )maxsizec                @    d t          j        |           D             S )Nc                    i | ]
}|j         |S r"   )name).0eps     r   
<dictcomp>z&detect_entrypoints.<locals>.<dictcomp>+   s)         r   )group)importlib_metadataentry_points)entry_point_names    r   detect_entrypointsr/   )   s2     0=DTUUU   r   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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d
S )%CreationDispatchz9Simple backend dispatch for collection-creation functionsz dict[str, BackendEntrypointType]_lookupstr_module_name_config_field_defaulttype[BackendEntrypointType]_entrypoint_classNmodule_namedefaultentrypoint_classr'   
str | Nonec                h    i | _         || _        | d| _        || _        || _        |r	|| _        d S d S )Nz.backend)r4   r6   r7   r8   r:   r   )selfr;   r<   r=   r'   s        r   __init__zCreationDispatch.__init__?   sP     ' +555!1 	! DMMM	! 	!r   backendr0   returnc                    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 )
isinstancer:   
ValueErrortyper4   )r@   r'   rB   s      r   register_backendz!CreationDispatch.register_backendN   sf     '4#9:: 	')' 'G}}' '  
 %Tr   c                   	 | j         |         }|S # t          $ rW t          d| j         d          }||v r8|                     | ||                                                               cY S Y nw xY wt          d|           )z%Return the desired backend entrypointzdask.z	.backendsz#No backend dispatch registered for )r4   KeyErrorr/   r6   rH   loadrF   )r@   rB   implentrypointss       r   dispatchzCreationDispatch.dispatch[   s    	<(D K  	U 	U 	U,-QT5F-Q-Q-QRRK+%%,,W6Qk'6J6O6O6Q6Q6S6STTTTT &%	U HwHHIIIs    AA21A2c                N    t          j        | j        | j                  p| j        S )z%Return the desired collection backend)r
   getr7   r8   )r@   s    r   rB   zCreationDispatch.backendh   s"     z$,dm<<MMr   valuec                2    t          d| j         d          )Nz#Set the backend by configuring the z option)RuntimeErrorr7   )r@   rQ   s     r   rB   zCreationDispatch.backendm   s%    M$2DMMM
 
 	
r   jCallable[[Callable[BackendFuncParams, BackendFuncReturn]], Callable[BackendFuncParams, BackendFuncReturn]]c                     d fd}|S )zRegister dispatchable functionfn.Callable[BackendFuncParams, BackendFuncReturn]rC   c                    p| j                                       }|                    |            t          |           fd            }|_         |S )Nc            	         t                    }	  || i |S # t          $ r9} t          |          dt          |           dj         d|           |d }~ww xY w)Nz$An error occurred while calling the z method registered to the z backend.
Original Message: )getattr	ExceptionrG   r   rB   )argskwargsfuncedispatch_namer@   s       r   wrapperzECreationDispatch.register_inplace.<locals>.decorator.<locals>.wrapper   s    t]3340000    !$q''1x~~ 1 148L1 1-.1 1  	s    
A4AA)r   rN   __setattr__r   )rV   
dispatcherra   r`   rB   r'   r@   s      @r   	decoratorz4CreationDispatch.register_inplace.<locals>.decorator}   sv     !/BKMw//J""="5552YY	 	 	 	 	 Y	  -GNr   )rV   rW   rC   rW   r"   )r@   rB   r'   rd   s   ``` r   register_inplacez!CreationDispatch.register_inplaces   s5    	 	 	 	 	 	 	 	, r   itemc                V    |                      | j                  }t          ||          S )zJ
        Return the appropriate attribute for the current backend
        )rN   rB   rZ   )r@   rf   rB   s      r   __getattr__zCreationDispatch.__getattr__   s'     ----w%%%r   )N)r;   r5   r<   r5   r=   r9   r'   r>   )r'   r5   rB   r0   rC   r0   )rB   r5   )rC   r5   )rQ   r5   )rB   r5   r'   r>   rC   rT   )rf   r5   )r   r   r   r   __annotations__rA   rH   rN   propertyrB   setterre   rh   r"   r   r   r3   r3   6   s        CC----MMM2222  ! ! ! ! !   J J J J N N N XN ^
 
 
 ^
           D& & & & & &r   r3   )
__future__r   collections.abcr   	functoolsr   r   typingr   r   r	   r,   daskr
   
dask.utilsr   typing_extensionsr   r   r   r   r/   r0   r3   r"   r   r   <module>rs      s   " " " " " " $ $ $ $ $ $ & & & & & & & & 2 2 2 2 2 2 2 2 2 2                 5++++++!	"566 344" " " " " " " ", 1    
!   d& d& d& d& d&w45 d& d& d& d& d&r   