o
    oi                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZ eeZG dd dZeddd	Zed
dd	Zeddd	ZedZedZedZedZedZedZedZedZdS )    N)
ModuleType)ListOptional)InstallationModekornia_configc                   @   sv   e Zd ZU dZdZeed< ddededdfdd	Zdeddfd
dZ	dddZ
dedefddZdee fddZdS )
LazyLoadera   A class that implements lazy loading for Python modules.

    This class defers the import of a module until an attribute of the module is accessed.
    It helps in reducing the initial load time and memory usage of a script, especially when
    dealing with large or optional dependencies that might not be used in every execution.

    Attributes:
        module_name: The name of the module to be lazily loaded.
        module: The actual module object, initialized to None and loaded upon first access.

    Fauto_installmodule_namedev_dependencyreturnNc                 C   s   || _ d| _|| _dS )a  Initialize the LazyLoader with the name of the module.

        Args:
            module_name: The name of the module to be lazily loaded.
            dev_dependency: If the dependency is required in the dev environment.
                If True, the module will be loaded in the dev environment.
                If False, the module will not be loaded in the dev environment.

        N)r	   moduler
   )selfr	   r
    r   H/home/ubuntu/.local/lib/python3.10/site-packages/kornia/core/external.py__init__-   s   

zLazyLoader.__init__c                 C   s4   t d| d tjtjdddd|gddd d S )	NzInstalling `z` ...z-mpipinstallz-UF)shellcheck)loggerinfo
subprocessrunsys
executable)r   r	   r   r   r   _install_package;   s   "zLazyLoader._install_packagec              
   C   s  | j s/dtjv rtd| j d dS ztr$td| j d W dS W n	 ty.   Y nw | jdu rz
t	
| j| _W dS  ty } ztjjtjksP| jrW| | j n}tjjtjkrd}td| j d}|r| d	ksw| d
kr| | j t	
| j| _d}n9| dks| dkrd| _| | j t	
| j| _d}n| dks| dkrtd| j d|td}|skntjjtjkrtd| j d|t	
| j| _W Y d}~dS d}~ww dS )a  Load the module if it hasn't been loaded yet.

        This method is called internally when an attribute of the module is accessed for the first time. It attempts to
        import the module and raises an ImportError with a custom message if the module is not installed.
        z--doctest-modulesz'Doctest detected, skipping loading of ''Nz&Sphinx detected, skipping loading of 'TzOptional dependency 'z' is not installed. You may silent this prompt by `kornia_config.lazyloader.installation_mode = 'auto'`. Do you wish to install the dependency? [Y]es, [N]o, [A]ll.yyesFaallnnoz@' is not installed. Please install it to use this functionality.z-Invalid input. Please enter 'Y', 'N', or 'A'.)r
   r   argvr   r   r	   __sphinx_build__	NameErrorr   	importlibimport_moduleImportErrorr   
lazyloaderinstallation_moder   AUTOr   r   ASKinputlowerRAISE)r   eto_ask
if_installr   r   r   _load?   sh   

zLazyLoader._loaditemc                 C   s   |    t| j|S )a  Load the module (if not already loaded) and returns the requested attribute.

        This method is called when an attribute of the LazyLoader instance is accessed.
        It ensures that the module is loaded and then returns the requested attribute.

        Args:
            item: The name of the attribute to be accessed.

        Returns:
            The requested attribute of the loaded module.

        )r3   getattrr   )r   r4   r   r   r   __getattr__v   s   zLazyLoader.__getattr__c                 C   s   |    t| jS )a|  Load the module (if not already loaded) and returns the list of attributes of the module.

        This method is called when the built-in dir() function is used on the LazyLoader instance.
        It ensures that the module is loaded and then returns the list of attributes of the module.

        Returns:
            list: The list of attributes of the loaded module.

        )r3   dirr   )r   r   r   r   __dir__   s   

zLazyLoader.__dir__)F)r   N)__name__
__module____qualname____doc__r   bool__annotations__strr   r   r3   objectr6   r   r8   r   r   r   r   r      s   
 
7r   numpyT)r
   z	PIL.Imageonnx	diffuserstransformersonnxruntimeboxmotsegmentation_models_pytorchbasicsrrequestsivy)r&   loggingr   r   typesr   typingr   r   kornia.configr   r   	getLoggerr9   r   r   rA   PILImagerB   rC   rD   rE   rF   rG   rH   rI   rJ   r   r   r   r   <module>   s(   
z