
    IZj                     |   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZmZ dZdZdZdZdZdZdZdZ G d	 d
e          Zd+dZer!d dlZd dlZd dlZd dlZd dl Z d dl!Z!d dl"Z"d dl#Z#np ed          \  ZZ ed          \  ZZ ed          \  ZZ ed          \  Z"Z ed          \  ZZ ed          \  Z!Z ed          \  Z Z ed          \  Z#Z ed          d,d            Z$ddd-d"Z%ddd-d#Z&ddd-d$Z'ddd-d%Z(ddd-d&Z)ddd-d'Z*ddd-d(Z+ddd-d)Z,g d*Z-dS ).    )annotationsN)	lru_cache)import_module)	find_spec)
ModuleType)TYPE_CHECKINGAnyClassVarHashablecastTc                  X     e Zd ZU dZdZddddddd	d
Zded<   d fdZddZddZ	 xZ
S )_LazyModulea/  
    Module that can act both as a lazy-loader and as a proxy.

    Notes
    -----
    We do NOT register this module with `sys.modules` so as not to cause
    confusion in the global environment. This way we have a valid proxy
    module for our own use, but it lives _exclusively_ within lance.

    Tznp.zpd.zpl.ztorch.ztf.zray.zlance.)numpypandaspolarstorch
tensorflowraylancezClassVar[dict[str, str]]_mod_pfxmodule_namestrmodule_availableboolreturnNonec                   || _         || _        t                      | _        t	                                          |           dS )a  
        Initialise lazy-loading proxy module.

        Parameters
        ----------
        module_name : str
            the name of the module to lazy-load (if available).

        module_available : bool
            indicate if the referenced module is actually available (we will proxy it
            in both cases, but raise a helpful error when invoked if it doesn't exist).

        N)_module_available_module_nameglobals_globalssuper__init__)selfr   r   	__class__s      `/Users/jameslopez/projects/MentorCore/.venv/lib/python3.11/site-packages/lancedb/dependencies.pyr#   z_LazyModule.__init__<   s>    & "2'		%%%%%    r   c                    t          | j                  }|| j        | j        <   | j                            |j                   |S )N)r   __name__r!   r   __dict__update)r$   modules     r&   _importz_LazyModule._importT   s=    t}--+1d'(V_---r'   attrr	   c                d   |dk    rt          | j        d|          | j        r$|                                 }t	          ||          S |dk    r| j        S t          j        d|          r|dk    rd S | j                            | j        d          }t          | | d| j        d          d )	N__wrapped__z object has no attribute r)   z	^__\w+__$__version__ z
 requires z module to be installed)
AttributeErrorr   r   r-   getattrrematchr   getModuleNotFoundError)r$   r.   r,   pfxs       r&   __getattr__z_LazyModule.__getattr__[   s     =   $IIII  
 ! 	\\^^F64((( Z$$XlD)) 		dm.C.C 4 -##D$5r::C%TTT(9TTT r'   )r   r   r   r   r   r   )r   r   )r.   r	   r   r	   )r)   
__module____qualname____doc____lazy__r   __annotations__r#   r-   r:   __classcell__)r%   s   @r&   r   r   $   s         	 	 H * *H    & & & & & &0          r'   r   r   r   r   tuple[ModuleType, bool]c                    | t           j        v rt           j        |          dfS 	 t          |           }|du p|j        du  }n# t          $ r d}Y nw xY wt          | |          |fS )a  
    Lazy import the given module; avoids up-front import costs.

    Parameters
    ----------
    module_name : str
        name of the module to import, eg: "polars".

    Notes
    -----
    If the requested module is not available (eg: has not been installed), a proxy
    module is created in its place, which raises an exception on any attribute
    access. This allows for import and use as normal, without requiring explicit
    guard conditions - if the module is never used, no exception occurs; if it
    is, then a helpful exception is raised.

    Returns
    -------
    tuple of (Module, bool)
        A lazy-loading module and a boolean indicating if the requested/underlying
        module exists (if not, the returned module is a proxy).

    TNF)r   r   )sysmodulesr   loaderr8   r   )r   module_specr   s      r&   _lazy_importrG   x   s    2 ck!!{;'--!,, +t 3 Q{7IT7QR ! ! ! ! 	#-	
 	
 	
 	 s   A AAr   r   r   r   datasetsr   r   r   )maxsizeclstypetype_r   c                    	 t          fd|                                 D                       S # t          $ r Y dS w xY w)Nc              3  @   K   | ]} d t          |          v V  dS ).N)r   ).0orL   s     r&   	<genexpr>z_might_be.<locals>.<genexpr>   s4      <<Qe;;;#a&&(<<<<<<r'   F)anymro	TypeError)rJ   rL   s    `r&   	_might_berV      sU    <<<<#''))<<<<<<   uus   ,0 
>>)
check_typeobjr	   rW   c               x    t           o3t          t          t          |rt	          |           n|           d          S )Nr   )_NUMPY_AVAILABLErV   r   r   rK   rX   rW   s     r&   _check_for_numpyr\      9     	XJ7tCyyyC88'! ! r'   c               x    t           o3t          t          t          |rt	          |           n|           d          S )Nr   )_PANDAS_AVAILABLErV   r   r   rK   r[   s     r&   _check_for_pandasr`      9     XJ7tCyyyC88(" " r'   c               x    t           o3t          t          t          |rt	          |           n|           d          S )Nr   )_POLARS_AVAILABLErV   r   r   rK   r[   s     r&   _check_for_polarsrd      ra   r'   c               x    t           o3t          t          t          |rt	          |           n|           d          S )Nr   )_TORCH_AVAILABLErV   r   r   rK   r[   s     r&   _check_for_torchrg      r]   r'   c               x    t           o3t          t          t          |rt	          |           n|           d          S )NrH   )_HUGGING_FACE_AVAILABLErV   r   r   rK   r[   s     r&   _check_for_hugging_facerj      s9    " yXJ7tCyyyC88*( ( r'   c               x    t           o3t          t          t          |rt	          |           n|           d          S )Nr   )_TENSORFLOW_AVAILABLErV   r   r   rK   r[   s     r&   _check_for_tensorflowrm      s9      YXJ7tCyyyC88,& & r'   c               x    t           o3t          t          t          |rt	          |           n|           d          S )Nr   )_RAY_AVAILABLErV   r   r   rK   r[   s     r&   _check_for_rayrp      s9     iXJ7tCyyyC88%  r'   c               x    t           o3t          t          t          |rt	          |           n|           d          S )Nr   )_LANCE_AVAILABLErV   r   r   rK   r[   s     r&   _check_for_lancers      r]   r'   )rH   r   r   r   r   r   r   r   rj   r\   r`   rd   rm   rg   rp   rs   r   rZ   r_   rc   rf   ri   rl   ro   rr   )r   r   r   rA   )rJ   rK   rL   r   r   r   )rX   r	   rW   r   r   r   ).
__future__r   r5   rC   	functoolsr   	importlibr   importlib.utilr   typesr   typingr   r	   r
   r   r   rZ   r_   rc   rf   ri   rl   ro   rr   r   rG   rH   r   r   r   r   r   r   r   rV   r\   r`   rd   rg   rj   rm   rp   rs   __all__ r'   r&   <module>r|      sp    # " " " " " 				 



       # # # # # # $ $ $ $ $ $       ? ? ? ? ? ? ? ? ? ? ? ? ? ?       Q Q Q Q Q* Q Q Qh+ + + +\  4OOOLLLMMMMMMJJJLLLLLLL +l733E ,X 6 6F ,X 6 6F*l733E(4Z(@(@%H%(4\(B(B%J%&,u--C*l733E 4    6:       7;       7;       6:       =A       ;?       48       6:        r'   