
    Nj#                        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mZ d dlZd dlmZ d dlmZ  ej$                  e      Z G d	 d
e      Z G d de      ZdZ ej0                  d      ZddZddZy)    )annotationsN)Iterator)import_module)metadata)AnyProtocol)Parallel)tqdmc                  :     e Zd ZdZdd fdZd fdZddZ xZS )	ProgressParallelzIA drop-in replacement for joblib.Parallel that shows a tqdm progress bar.c                @    || _         || _        t        |   |i | y)a  Initialize the ProgressParallel object.

        :param use_tqdm: Whether to show the progress bar.
        :param total: Total number of tasks (batches) you expect to process. If None,
                    it updates the total dynamically to the number of dispatched tasks.
        :param *args: Additional arguments to pass to `Parallel.__init__`.
        :param **kwargs: Additional keyword arguments to pass to `Parallel.__init__`.
        N)	_use_tqdm_totalsuper__init__)selfuse_tqdmtotalargskwargs	__class__s        `/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/model2vec/utils.pyr   zProgressParallel.__init__   s%     "$)&)    c                    t        | j                   | j                        5 | _        | j                  | _        t	        |   |i |cddd       S # 1 sw Y   yxY w)zCreate a tqdm context.)disabler   N)r
   r   r   _pbarr   __call__)r   r   r   r   s      r   r   zProgressParallel.__call__!   sF    dnn,DKK@DJDJ7#T4V4 A@@s   %AAc                    | j                   | j                  | j                  _        | j                  | j                  _        | j                  j                          y)zEHook called by joblib as tasks complete. We update the tqdm bar here.N)r   n_dispatched_tasksr   r   n_completed_tasksnrefresh)r   s    r   print_progresszProgressParallel.print_progress'   s?    ;;#66DJJ--



r   )TN)
r   boolr   z
int | Noner   r   r   r   returnNone)r   r   r   r   r%   r   )r%   r&   )__name__
__module____qualname____doc__r   r   r#   __classcell__)r   s   @r   r   r      s    S*5r   r   c                      e Zd ZdZddZy)SafeOpenProtocolz&Protocol to fix safetensors safe open.c                     y)zGet a tensor.N )r   keys     r   
get_tensorzSafeOpenProtocol.get_tensor4   s    r   N)r0   strr%   z
np.ndarray)r'   r(   r)   r*   r1   r/   r   r   r-   r-   1   s
    0r   r-   ))zscikit-learnsklearnz[=<>!]+c              #  z  K   	 t        |       }|j                  d      xs g }|D ]o  } | j	                  dd      ^}}|s|d   j	                  d	      d
   j                  d      }||k(  sGt        j	                  |      ^}}	|j                          q y# t        $ r}t        d|  d|       d}~ww xY ww)zGet the extras of the package.z)Could not retrieve metadata for package 'z': NzRequires-Dist;   )maxsplitr   z==z "')r   	ExceptionImportErrorget_allsplitstrip	_DIVIDERS)
packageextramessageeall_packagesnamerestfound_extraprefix_s
             r   get_package_extrasrI   =   s     W7# ???39rLmmC!m4tq'---b177?Ke#&__T2
lln$  	  WEgYcRSQTUVVWs3   B;B 1B;+B;-,B;	B8"B33B88B;c           
         t        t              j                  | |       } 	 t        |        y# t        $ r t	        d|  d| d| d      w xY w)z Check if a module is importable.`z5`, is required. Please reinstall model2vec with the `z ` extra. `pip install model2vec[z]`N)dict_MODULE_MAPgetr   r:   )moduler@   s     r   
importablerP   O   s_    +""662F
f 
xLUGSstyszz|}
 	

s	   - A)r?   r2   r@   r2   r%   zIterator[str])rO   r2   r@   r2   r%   r&   )
__future__r   loggingrecollections.abcr   	importlibr   importlib.metadatar   typingr   r   numpynpjoblibr	   r
   	getLoggerr'   loggerr   r-   rM   compiler>   rI   rP   r/   r   r   <module>r^      so    "  	 $ # '     			8	$x @x  -BJJz"	%$
r   