o
    Nrf                     @  s   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 dZedddd Ze
dddZG dd de	e ZdS )    )annotations)Callable)	lru_cachewraps)TYPE_CHECKINGGenericTypeVar)config)importlib_metadata)funcname)	ParamSpecBackendFuncParamsBackendFuncReturnc                   @  s(   e Zd ZdZedd Zed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                 C     t )z7Return a dispatch function to move data to this backendNotImplementedError)cls r   V/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/dask/backends.pyto_backend_dispatch      z)DaskBackendEntrypoint.to_backend_dispatchc                 C  r   )z)Create a new collection with this backendr   )datar   r   r   
to_backend"   r   z DaskBackendEntrypoint.to_backendN)__name__
__module____qualname____doc__classmethodr   staticmethodr   r   r   r   r   r      s    

r      )maxsizec                 C  s   dd t j| dD S )Nc                 S  s   i | ]}|j |qS r   )name).0epr   r   r   
<dictcomp>*   s    z&detect_entrypoints.<locals>.<dictcomp>)group)r
   entry_points)Zentry_point_namer   r   r   detect_entrypoints(   s   
r(   BackendEntrypointType)boundc                   @  s   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dZd(ddZd)ddZed*ddZ	e	j
d+ddZ		d,d-d!d"Zd.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_class_entrypoint_rootNdaskmodule_namedefaultentrypoint_classr"   
str | Noneentrypoint_rootc                 C  s<   i | _ || _| d| _|| _|| _|| _|r|| _d S d S )Nz.backend)r,   r.   r/   r0   r2   r3   r   )selfr5   r6   r7   r"   r9   r   r   r   __init__?   s   
zCreationDispatch.__init__backendr)   returnc                 C  s4   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 )
isinstancer2   
ValueErrortyper,   )r:   r"   r<   r   r   r   register_backendP   s   
z!CreationDispatch.register_backendc                 C  sl   z| j | }W |S  ty.   t| j d| j d}||v r,| |||    Y S Y nw td| )z%Return the desired backend entrypoint.z	.backendsz#No backend dispatch registered for )r,   KeyErrorr(   r3   r.   rA   loadr?   )r:   r<   implentrypointsr   r   r   dispatch]   s   		zCreationDispatch.dispatchc                 C  s   t | j| jp
| jS )z%Return the desired collection backend)r	   getr/   r0   )r:   r   r   r   r<   l   s   zCreationDispatch.backendvaluec                 C  s   t d| j d)Nz#Set the backend by configuring the z option)RuntimeErrorr/   )r:   rI   r   r   r   r<   q   s   jCallable[[Callable[BackendFuncParams, BackendFuncReturn]], Callable[BackendFuncParams, BackendFuncReturn]]c                   s   d fdd}|S )zRegister dispatchable functionfn.Callable[BackendFuncParams, BackendFuncReturn]r=   c                   s@   p| j  }| |  t|  fdd} |_ |S )Nc               
     sZ   t  }z|| i |W S  ty, } zt|dt| dj d| |d }~ww )Nz$An error occurred while calling the z method registered to the z backend.
Original Message: )getattr	Exceptionr@   r   r<   )argskwargsfunce)dispatch_namer:   r   r   wrapper   s   
zECreationDispatch.register_inplace.<locals>.decorator.<locals>.wrapper)r   rG   __setattr__r   )rL   
dispatcherrU   r<   r"   r:   )rT   r   	decorator   s   

z4CreationDispatch.register_inplace.<locals>.decoratorN)rL   rM   r=   rM   r   )r:   r<   r"   rY   r   rX   r   register_inplacew   s   
z!CreationDispatch.register_inplaceitemc                 C  s   |  | j}t||S )zJ
        Return the appropriate attribute for the current backend
        )rG   r<   rN   )r:   r[   r<   r   r   r   __getattr__   s   
zCreationDispatch.__getattr__)Nr4   )
r5   r-   r6   r-   r7   r1   r"   r8   r9   r-   )r"   r-   r<   r)   r=   r)   )r<   r-   )r=   r-   )rI   r-   )N)r<   r-   r"   r8   r=   rK   )r[   r-   )r   r   r   r   __annotations__r;   rA   rG   propertyr<   setterrZ   r\   r   r   r   r   r+   5   s(   
 

"r+   N)
__future__r   collections.abcr   	functoolsr   r   typingr   r   r   r4   r	   Zdask._compatibilityr
   Z
dask.utilsr   Ztyping_extensionsr   r   r   r   r(   r)   r+   r   r   r   r   <module>   s&    
