o
    i,                     @  s  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 er:d dlmZ d	Zd	Zd	Zd	Zd	Zd	Zd	Zd	Zd	Zd	Zd	Zd	Zd	Zd	Z G d
d deZ!dIddZ"erd 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*d dl+Z+d dl,Z,d dl-Z-d dl.Z.d dl/Z/d dl0Z0d dl1Z1d dl2Z2d dl3Z3d dl4Z4d dl5Z4d dl6Z6d dl7Z7nxe"d\Z#Z8e"d\Z$Z8e"d\Z%Z8e"d\Z&Z8e"d\Z'Z8e"d\Z(Ze"d\Z)Z9e"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\Z0Ze"d \Z1Ze"d!\Z2Ze"d"\Z3Ze"d#\Z4Ze"d$\Z7Ze"d%\Z6Z edJd*d+Z:d	d,dKd0d1Z;d	d,dKd2d3Z<d	d,dKd4d5Z=d	d,dKd6d7Z>d	d,dKd8d9Z?d	d,dKd:d;Z@	<	=		>	dLdMdFdGZAg dHZBdS )N    )annotationsN)cache)import_module)	find_spec)
ModuleType)TYPE_CHECKINGAnyClassVarcast)HashableTc                      sR   e Zd ZU dZdZdddddZded	< d fddZdddZdddZ	  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 polars.
    Tznp.zpd.zpa.zpc.)numpypandaspyarrowpolars_cloudzClassVar[dict[str, str]]_mod_pfxmodule_namestrmodule_availableboolreturnNonec                  s$   || _ || _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__ K/home/app/Keep/.python/lib/python3.10/site-packages/polars/_dependencies.pyr   2   s   z_LazyModule.__init__r   c                 C  s(   t | j}|| j| j< | j|j |S N)r   __name__r   r   __dict__update)r   moduler!   r!   r"   _importI   s   
z_LazyModule._importnamer   c                 C  s   |dkr| j d|}t|| jr|  }t||S |dkr#| j S td|r/|dkr/d S | j| j d}| | d| j d}t	|d )	N__wrapped__z object has no attribute r$   z	^__\w+__$__version__ z
 requires z module to be installed)
r   AttributeErrorr   r(   getattrrematchr   getModuleNotFoundError)r   r)   msgr'   pfxr!   r!   r"   __getattr__P   s   

z_LazyModule.__getattr__)r   r   r   r   r   r   )r   r   )r)   r   r   r   )r$   
__module____qualname____doc__Z__lazy__r   __annotations__r   r(   r5   __classcell__r!   r!   r   r"   r      s   
 

r   r   r   r   tuple[ModuleType, bool]c                 C  s`   | t jv rt j|  dfS zt| }|du p|jdu  }W n ty'   d}Y nw t| |d|fS )a  
    Lazy import the given module; avoids up-front import costs.

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

    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   loaderr2   r   )r   Zmodule_specr   r!   r!   r"   _lazy_importk   s   
r?   dataclasseshtmljsonpickle
subprocessaltairboto3	deltalakefsspecgeventgreat_tables
hypothesisr   r   r   r   pydantic	pyicebergtorchpytzclstypetype_r   c                   s2   zt  fdd|  D W S  ty   Y dS w )Nc                 3  s"    | ]}  d t |v V  qdS ).Nr   ).0orR   r!   r"   	<genexpr>   s     z_might_be.<locals>.<genexpr>F)anymro	TypeError)rP   rR   r!   rW   r"   	_might_be   s
   r\   )
check_typeobjr   r]   c                C      t ottd|rt| n| dS )Nr   r   )_NUMPY_AVAILABLEr\   r
   rQ   r^   r]   r!   r!   r"   _check_for_numpy      rb   c                C  r_   )Nr   r   )_PANDAS_AVAILABLEr\   r
   rQ   ra   r!   r!   r"   _check_for_pandas   rc   re   c                C  r_   )Nr   r   )_PYARROW_AVAILABLEr\   r
   rQ   ra   r!   r!   r"   _check_for_pyarrow   rc   rg   c                C  r_   )Nr   rL   )_PYDANTIC_AVAILABLEr\   r
   rQ   ra   r!   r!   r"   _check_for_pydantic   rc   ri   c                C  r_   )Nr   rN   )_TORCH_AVAILABLEr\   r
   rQ   ra   r!   r!   r"   _check_for_torch   rc   rk   c                C  r_   )Nr   rO   )_PYTZ_AVAILABLEr\   r
   rQ   ra   r!   r!   r"   _check_for_pytz   rc   rm   required package	not foundrequires
err_prefix
err_suffixmin_versionstr | tuple[int, ...] | Nonemin_err_prefixinstall_message
str | Nonec              
   C  s
  ddl m} ddlm} | ddd }zt| }	W n7 tyQ   |r+|d dnd}
|r7d|d nd}|
 d|  d| d	|pJd
| d }t|dw |r||}||	j	}||k r| d| dd
dd |D  dd
dd |D  d}|||	S )aj  
    Import an optional dependency, returning the module.

    Parameters
    ----------
    module_name : str
        Name of the dependency to import.
    err_prefix : str, optional
        Error prefix to use in the raised exception (appears before the module name).
    err_suffix: str, optional
        Error suffix to use in the raised exception (follows the module name).
    min_version : {str, tuple[int]}, optional
        If a minimum module version is required, specify it here.
    min_err_prefix : str, optional
        Override the standard "requires" prefix for the minimum version error message.
    install_message : str, optional
        Override the standard "Please install it using..." exception message fragment.

    Examples
    --------
    >>> from polars._dependencies import import_optional
    >>> import_optional(
    ...     "definitely_a_real_module",
    ...     err_prefix="super-important package",
    ... )  # doctest: +SKIP
    ImportError: super-important package 'definitely_a_real_module' not installed.
    Please install it using the command `pip install definitely_a_real_module`.
    r   )parse_version)ModuleUpgradeRequiredErrorrS       r,   'z.
z.Please install using the command `pip install z`.Nc                 s      | ]}t |V  qd S r#   rT   rU   vr!   r!   r"   rX   2      z"import_optional.<locals>.<genexpr>z or higher (found c                 s  r}   r#   rT   r~   r!   r!   r"   rX   3  r   ))Zpolars._utils.variousrx   Zpolars.exceptionsry   splitr   ImportErrorstripr2   r+   join)r   rq   rr   rs   ru   rv   rx   ry   Zmodule_rootr'   prefixsuffixZerr_messageZmod_versionr3   r!   r!   r"   import_optional   s4   $

	
r   )&r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   r   r   r   rL   rM   r   rN   rO   rb   re   rg   ri   rk   rm   _ALTAIR_AVAILABLE_DELTALAKE_AVAILABLE_FSSPEC_AVAILABLE_GEVENT_AVAILABLE_GREAT_TABLES_AVAILABLE_HYPOTHESIS_AVAILABLEr`   rd   _POLARS_CLOUD_AVAILABLErf   rh   _PYICEBERG_AVAILABLErj   )r   r   r   r;   )rP   rQ   rR   r   r   r   )r^   r   r]   r   r   r   )rn   ro   Nrp   N)r   r   rq   r   rr   r   rs   rt   ru   r   rv   rw   r   r   )C
__future__r   r/   r<   	functoolsr   	importlibr   importlib.utilr   typesr   typingr   r   r	   r
   collections.abcr   r   r   r   r   r   r   r`   rd   r   rf   rh   r   rj   rl   r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r   r   r   r   rL   rM   Zpyiceberg.schemarO   rN   _Z_BOTO3_AVAILABLEr\   rb   re   rg   ri   rk   rm   r   __all__r!   r!   r!   r"   <module>   s    
M-

A