a
    tDf                     @  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rd 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  s   t dS )z7Return a dispatch function to move data to this backendNNotImplementedError)cls r   Z/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/dask/backends.pyto_backend_dispatch   s    z)DaskBackendEntrypoint.to_backend_dispatchc                 C  s   t dS )z)Create a new collection with this backendNr   )datar   r   r   
to_backend"   s    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
   Z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dddddZddddddZddddZeddddZ	e	j
ddddZ	d%dddddd Zdd!d"d#ZdS )&CreationDispatchz9Simple backend dispatch for collection-creation functionsz dict[str, BackendEntrypointType]_lookupstr_module_name_config_field_defaultztype[BackendEntrypointType]_entrypoint_class_entrypoint_rootNdaskz
str | None)module_namedefaultentrypoint_classr    entrypoint_rootc                 C  s8   i | _ || _| d| _|| _|| _|| _|r4|| _d S )Nz.backend)r)   r+   r,   r-   r.   r/   r   )selfr1   r2   r3   r    r4   r   r   r   __init__?   s    zCreationDispatch.__init__r&   )r    backend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 )
isinstancer.   
ValueErrortyper)   )r5   r    r7   r   r   r   register_backendP   s    
z!CreationDispatch.register_backend)r7   c                 C  sr   z| j | }W nL tyZ   t| j d| j d}||v rV| |||    Y S Y n0 |S td| dS )z%Return the desired backend entrypoint.z	.backendsz#No backend dispatch registered for N)r)   KeyErrorr%   r/   r+   r<   loadr:   )r5   r7   implZentrypointsr   r   r   dispatch]   s     zCreationDispatch.dispatch)r8   c                 C  s   t | j| jp| jS )z%Return the desired collection backend)r	   getr,   r-   )r5   r   r   r   r7   l   s    zCreationDispatch.backend)valuec                 C  s   t d| j dd S )Nz#Set the backend by configuring the z option)RuntimeErrorr,   )r5   rC   r   r   r   r7   q   s    zjCallable[[Callable[BackendFuncParams, BackendFuncReturn]], Callable[BackendFuncParams, BackendFuncReturn]])r7   r    r8   c                   s   ddd fdd}|S )zRegister dispatchable functionz.Callable[BackendFuncParams, BackendFuncReturn])fnr8   c                   s@   p| j  }| |  t|  fdd} |_ |S )Nc               
     sj   t  }z|| i |W S  tyd } z2t|dt| dj d| |W Y d }~n
d }~0 0 d S )Nz$An error occurred while calling the z method registered to the z backend.
Original Message: )getattr	Exceptionr;   r   r7   )argskwargsfunce)dispatch_namer5   r   r   wrapper   s    
zECreationDispatch.register_inplace.<locals>.decorator.<locals>.wrapper)r   rA   __setattr__r   )rE   
dispatcherrM   r7   r    r5   )rL   r   	decorator   s    

z4CreationDispatch.register_inplace.<locals>.decoratorr   )r5   r7   r    rQ   r   rP   r   register_inplacew   s    
z!CreationDispatch.register_inplace)itemc                 C  s   |  | j}t||S )zJ
        Return the appropriate attribute for the current backend
        )rA   r7   rF   )r5   rS   r7   r   r   r   __getattr__   s    zCreationDispatch.__getattr__)Nr0   )N)r   r   r   r   __annotations__r6   r<   rA   propertyr7   setterrR   rT   r   r   r   r   r(   5   s&   
   "r(   N)
__future__r   collections.abcr   	functoolsr   r   typingr   r   r   r0   r	   Zdask._compatibilityr
   Z
dask.utilsr   Ztyping_extensionsr   r   r   r   r%   r&   r(   r   r   r   r   <module>   s$   
